Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Win32API::File crateFile[D[D[D[D[D[D[De[C[C[C[D[D[Da[2~teFile "r" sets $create to OPEN_EXISTING #8941

Closed
p5pRT opened this issue Jun 21, 2007 · 12 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 21, 2007

Migrated from rt.perl.org#43285 (status was 'resolved')

Searchable as RT43285$

@p5pRT
Copy link
Author

p5pRT commented Jun 21, 2007

From cygwin@cygwin.com

This is a bug report for perl from cygwin@​cygwin.com,
generated with the help of perlbug 1.35 running under perl 5.9.5.


I inspected my cygwin ext/Win32API/File/t/file.t failures further.
The problem is the language of the Windows error messages from GetLastError().
We check only against english, but german or other messages are not caught.

I added the german cases in the attached patch, but we really should
check either for the system locale = english or against the error
numbers from Win32API​::File​::_fileLastError()

$^E is always english BTW on cygwin, but we want to catch the API error.
$^E = "No such file or directory"
fileLastError() =~ /(not find the file|kann die angegebene Datei nicht finden)/i
_fileLastError() => 2



Flags​:
  category=library
  severity=high


Site configuration information for perl 5.9.5​:

Configured by rurban at Thu Jun 21 19​:08​:38 GMT 2007.

Summary of my perl5 (revision 5 version 9 subversion 5 patch 31441) configuration​:
  Platform​:
  osname=cygwin, osvers=1.5.24(0.15642), archname=cygwin-thread-multi-64int
  uname='cygwin_nt-5.1 reini 1.5.24(0.15642) 2007-01-31 10​:57 i686 cygwin '
  config_args='-de -Dmksymlinks -Duse64bitint -Dusethreads -Uusemymalloc -Doptimize=-O3 -Dman3ext=3pm -Dusesitecustomize -Dusedevel -DDEBUGGING'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=define, usemultiplicity=define
  useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
  use64bitint=define, use64bitall=undef, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='gcc', ccflags ='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -DDEBUGGING -fno-strict-aliasing -pipe',
  optimize='-O3 -g',
  cppflags='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -DDEBUGGING -fno-strict-aliasing -pipe'
  ccversion='', gccversion='3.4.4 (cygming special, gdc 0.12, using dmd 0.125)', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
  ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='ld2', ldflags =' -Wl,--enable-auto-import -s -L/usr/local/lib'
  libpth=/usr/local/lib /usr/lib /lib
  libs=-lgdbm -ldb -ldl -lcrypt -lgdbm_compat
  perllibs=-ldl -lcrypt -lgdbm_compat
  libc=/usr/lib/libc.a, so=dll, useshrplib=true, libperl=libperl.a
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' -s'
  cccdlflags=' ', lddlflags=' -s -L/usr/local/lib'

Locally applied patches​:
  DEVEL
  hints.cygwin.sh - ldflags -s
  lib-ExtUtils-Embed - insensitive against leading \\s
  lib-Test-Harness-Straps - $ENV{PERL5LIB} = ''
  major.version.cygwin.sh - cygperl-5_8.dll and not cygperl-5_8_x.dll
  #43268 Fix ext/Sys/Syslog/t/syslog.t #136 on cygwin
  libnet-1.21 - by jdhedden
  Pod​::Html and encodings - by Slaven Rezic


@​INC for perl 5.9.5​:
  /usr/lib/perl5/5.9/cygwin
  /usr/lib/perl5/5.9
  /usr/lib/perl5/site_perl/5.9/cygwin
  /usr/lib/perl5/site_perl/5.9
  /usr/lib/perl5/site_perl/5.9
  /usr/lib/perl5/vendor_perl/5.9/cygwin
  /usr/lib/perl5/vendor_perl/5.9
  /usr/lib/perl5/vendor_perl/5.9
  .


Environment for perl 5.9.5​:
  CYGWIN=server
  HOME=/home/rurban
  LANG (unset)
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/usr/bin​:/usr/sbin​:/usr/local/sbin​:/usr/local/bin​:/usr/bin​:/bin​:/usr/X11R6/bin​:/bin​:/usr/local/bin​:/cygdrive/c/WINDOWS​:/cygdrive/c/WINDOWS/System32​:/usr/X11R6/bin​:/cygdrive/c/bat​:/cygdrive/p/MSVS6/reskit​:/usr/lib/lapack
  PERL_BADLANG (unset)
  SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Jun 21, 2007

From @rurban

Sorry 'bout the subject. Please change to
"Win32API​::File tests language specific"

Attached is a patch to add german. And to beautify the output by adding
File​::Spec.

We should check for the system locale and if not english or german (new)
switch to numbers by using Win32API​::File​::_fileLastError().
--
Reini Urban

@p5pRT
Copy link
Author

p5pRT commented Jun 21, 2007

From @rurban

pl-Win32API-File-t.patch
--- perl-current/ext/Win32API/File/t/file.t.orig	2007-02-28 09:14:09.000000000 +0000
+++ perl-current/ext/Win32API/File/t/file.t	2007-06-21 21:37:02.593750000 +0000
@@ -2,6 +2,8 @@
 # Before `make install' is performed this script should be runnable with
 # `make test'. After `make install' it should work as `perl test.pl'
 
+# These test will only work on an english or german Windows!
+
 ######################### We start with some black magic to print on failure.
 
 BEGIN {
@@ -23,7 +25,9 @@
 # Win32API::File does an implicit "require Win32", but
 # the ../lib directory in @INC will no longer work once
 # we chdir() into the TEMP directory.
+
 use Win32;
+use File::Spec;
 use Carp;
 use Carp::Heavy;
 
@@ -37,19 +41,16 @@
 
 use strict qw(subs);
 
-$temp= $ENV{"TMP"};
-$temp= $ENV{"TEMP"}	unless -d $temp;
-$temp= "C:/Temp"	unless -d $temp;
-$temp= "."		unless -d $temp;
+$temp= File::Spec->tmpdir();
 $dir= "W32ApiF.tmp";
 
 $ENV{WINDIR} = $ENV{SYSTEMROOT} if not exists $ENV{WINDIR};
 
 chdir( $temp )
   or  die "# Can't cd to temp directory, $temp: $!\n";
-
+$tempdir = File::Spec->catdir($temp,$dir);
 if(  -d $dir  ) {
-    print "# deleting $temp\\$dir\\*\n" if glob "$dir/*";
+    print "# deleting ",File::Spec->catdir($temp,$dir,'*'),"\n" if glob "$dir/*";
 
     for (glob "$dir/*") {
 	chmod 0777, $_;
@@ -58,13 +59,13 @@
     rmdir $dir or die "Could not rmdir $dir: $!";
 }
 mkdir( $dir, 0777 )
-  or  die "# Can't create temp dir, $temp/$dir: $!\n";
-print "# chdir $temp\\$dir\n";
+  or  die "# Can't create temp dir, $tempdir: $!\n";
+print "# chdir $tempdir\n";
 chdir( $dir )
-  or  die "# Can't cd to my dir, $temp/$dir: $!\n";
-
+  or  die "# Can't cd to my dir, $tempdir: $!\n";
 $h1= createFile( "ReadOnly.txt", "r", { Attributes=>"r" } );
-$ok=  ! $h1  &&  fileLastError() =~ /not find the file?/i;
+# $^E is always english: "No such file or directory"
+$ok=  ! $h1  &&  fileLastError() =~ /(not find the file|kann die angegebene Datei nicht finden)/i;
 $ok or print "# ","".fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 2
 if(  ! $ok  ) {   CloseHandle($h1);   unlink("ReadOnly.txt");   }
@@ -78,13 +79,13 @@
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 4
 
 $h2= createFile( "ReadOnly.txt", "rcn" );
-$ok= ! $h2  &&  fileLastError() =~ /file exists?/i;
+$ok= ! $h2  &&  fileLastError() =~ /(file exists|Datei ist vorhanden)/i;
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 5
 if(  ! $ok  ) {   CloseHandle($h2);   }
 
 $h2= createFile( "ReadOnly.txt", "rwke" );
-$ok= ! $h2  &&  fileLastError() =~ /access is denied?/i;
+$ok= ! $h2  &&  fileLastError() =~ /(access is denied|Zugriff verweigert)/i;
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 6
 if(  ! $ok  ) {   CloseHandle($h2);   }
@@ -121,7 +122,7 @@
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 12
 
 $ok= ! ReadFile( $h2, $text, 80, $len, [] )
- &&  fileLastError() =~ /handle is invalid?/i;
+ &&  fileLastError() =~ /handle is invalid|Handle ist ung�ltig/i;
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 13
 
@@ -184,37 +185,37 @@
 CloseHandle( $h1 );
 
 $ok= ! DeleteFile( "ReadOnly.txt" )
- &&  fileLastError() =~ /access is denied?/i;
+ &&  fileLastError() =~ /access is denied|Zugriff verweigert/i;
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 23
 
 $ok= ! CopyFile( "ReadOnly.txt", "CanWrite.txt", 1 )
- &&  fileLastError() =~ /file exists?/i;
+ &&  fileLastError() =~ /file exists|Datei ist vorhanden/i;
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 24
 
 $ok= ! CopyFile( "CanWrite.txt", "ReadOnly.txt", 0 )
- &&  fileLastError() =~ /access is denied?/i;
+ &&  fileLastError() =~ /access is denied|Zugriff verweigert/i;
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 25
 
 $ok= ! MoveFile( "NoSuchFile", "NoSuchDest" )
- &&  fileLastError() =~ /not find the file/i;
+ &&  fileLastError() =~ /not find the file|kann die angegebene Datei nicht finden/i;
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 26
 
 $ok= ! MoveFileEx( "NoSuchFile", "NoSuchDest", 0 )
- &&  fileLastError() =~ /not find the file/i;
+ &&  fileLastError() =~ /not find the file|kann die angegebene Datei nicht finden/i;
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 27
 
 $ok= ! MoveFile( "ReadOnly.txt", "CanWrite.txt" )
- &&  fileLastError() =~ /file already exists?/i;
+ &&  fileLastError() =~ /file already exists?|kann nicht erstellt werden, wenn sie bereits vorhanden/i;
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 28
 
 $ok= ! MoveFileEx( "ReadOnly.txt", "CanWrite.txt", 0 )
- &&  fileLastError() =~ /file already exists?/i;
+ &&  fileLastError() =~ /file already exists?|kann nicht erstellt werden, wenn sie bereits vorhanden/i;
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 29
 
@@ -224,7 +225,7 @@
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 30
 
 $ok= ! MoveFileEx( "CanWrite.txt", "ReadOnly.cp", MOVEFILE_REPLACE_EXISTING )
- &&  fileLastError() =~ /access is denied?|cannot create/i;
+ &&  fileLastError() =~ /access is denied?|cannot create|Zugriff verweigert/i;
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 31
 
@@ -244,7 +245,7 @@
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 34
 
 $ok= ! DeleteFile( "Moved.cp" )
- &&  fileLastError() =~ /access is denied?/i;
+ &&  fileLastError() =~ /access is denied|Zugriff verweigert/i;
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 35
 

@p5pRT
Copy link
Author

p5pRT commented Jun 21, 2007

From [Unknown Contact. See original ticket]

Sorry 'bout the subject. Please change to
"Win32API​::File tests language specific"

Attached is a patch to add german. And to beautify the output by adding
File​::Spec.

We should check for the system locale and if not english or german (new)
switch to numbers by using Win32API​::File​::_fileLastError().
--
Reini Urban

@p5pRT
Copy link
Author

p5pRT commented Jun 22, 2007

From @rgs

On 21/06/07, via RT cygwin @​ cygwin. com <perlbug-followup@​perl.org> wrote​:

I inspected my cygwin ext/Win32API/File/t/file.t failures further.
The problem is the language of the Windows error messages from GetLastError().
We check only against english, but german or other messages are not caught.

I added the german cases in the attached patch, but we really should
check either for the system locale = english or against the error
numbers from Win32API​::File​::_fileLastError()

$^E is always english BTW on cygwin, but we want to catch the API error.
$^E = "No such file or directory"
fileLastError() =~ /(not find the file|kann die angegebene Datei nicht finden)/i
_fileLastError() => 2

I think that we should instead force the test to run in an english
locale. Via LC_ALL or something (I don't know how that works under
cygwin.)

@p5pRT
Copy link
Author

p5pRT commented Jun 22, 2007

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jun 22, 2007

From nospam-abuse@bloodgate.com

-----BEGIN PGP SIGNED MESSAGE-----
Hash​: SHA1

Moin,

On Thursday 21 June 2007 23​:54​:58 Reini Urban via RT wrote​:

Sorry 'bout the subject. Please change to
"Win32API​::File tests language specific"

Attached is a patch to add german. And to beautify the output by adding
File​::Spec.

We should check for the system locale and if not english or german (new)
switch to numbers by using Win32API​::File​::_fileLastError().

That patch seems to be a bit garbled (at least my Kwrite shows it as this)​:

$ok= ! ReadFile( $h2, $text, 80, $len, [] )
- - && fileLastError() =~ /handle is invalid?/i;
+ && fileLastError() =~ /handle is invalid|Handle ist ungltig/i;

it should be "ungültig" or better "ung.ltig" if you want to avoid writing
utf-8 in the test code :)

All the best,

Tels

- --
Signed on Fri Jun 22 12​:29​:53 2007 with key 0x93B84C15.
Get one of my photo posters​: http​://bloodgate.com/posters
PGP key on http​://bloodgate.com/tels.asc or per email.

"TT​: If I go to Blockbuster and rent a movie and watch it, am I a bad
person? Is that bad?
JV​: No, you're not a bad person. But you don't
have any right.
TT​: But I rented the movie. Why should it be
illegal?
JV​: Well then, you have to get a machine that's licensed to
show it. "

  -- Keith J. Winstein (TT) vs. Jack Valenty (JV) in
http​://tinyurl.com/2y65n
-----BEGIN PGP SIGNATURE-----
Version​: GnuPG v1.4.2 (GNU/Linux)

iQEVAwUBRnuswHcLPEOTuEwVAQJUuAf+Iuzpph8EuaqrGWW6wKscd6QS873kRkuV
w6IQ5ZZCbYzG0aKS47dOIARO9W8McmDR6NfJr1HIBhUAXheC+BgJkqqFrPkKSYaL
EJFstYy3bLdIULfCzWdWZovXuTy1O+Zwx1zdyyEyiLzQkvjWzREwAdDLbEtcYqOp
YRIGRIE98zeDQE9O11WDDrxxPXo7FH3BLyvqsiWifZbPNJhbwzpA+8fgBrTKySYH
A+sWNwIv5IYPZi9VSjSD06oPRFRYz9g7FETCTjwLZ4i/G/w5floD8Vmfy8YNCBSN
zVJYxri7tJwF/vhorvq018a1llp3x1vakYCuuDapl6jH1Sayo9ap9Q==
=7uSt
-----END PGP SIGNATURE-----

@p5pRT
Copy link
Author

p5pRT commented Jun 22, 2007

From @demerphq

On 6/21/07, Reini Urban via RT <perlbug-comment@​perl.org> wrote​:

Sorry 'bout the subject. Please change to
"Win32API​::File tests language specific"

Attached is a patch to add german. And to beautify the output by adding
File​::Spec.

We should check for the system locale and if not english or german (new)
switch to numbers by using Win32API​::File​::_fileLastError().

Actually id like to switch to using error numbers only. Theres no
point in supporting a few languages and also error codes. Error codes
alone should be sufficient.

So id prefer to see this patch changed to just use error codes and
ditch the language parsing outright.

cheers,
Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Jun 23, 2007

From @rurban

Attached patch switches to error numbers to handle
various foreign languages.

On Fri Jun 22 05​:25​:57 2007, demerphq wrote​:

On 6/21/07, Reini Urban via RT <perlbug-comment <!-- x --> at
perl.org> wrote​:

Sorry 'bout the subject. Please change to
"Win32API​::File tests language specific"

Attached is a patch to add german. And to beautify the output by adding
File​::Spec.

We should check for the system locale and if not english or german (new)
switch to numbers by using Win32API​::File​::_fileLastError().

Actually id like to switch to using error numbers only. Theres no
point in supporting a few languages and also error codes. Error codes
alone should be sufficient.

So id prefer to see this patch changed to just use error codes and
ditch the language parsing outright.

cheers,
Yves
--
Reini Urban

@p5pRT
Copy link
Author

p5pRT commented Jun 23, 2007

From @rurban

pl-#43285-Win32API-File-t.patch
--- ext/Win32API/File/t/file.t.orig	2007-02-28 09:14:09.000000000 +0000
+++ ext/Win32API/File/t/file.t	2007-06-23 18:09:27.468750000 +0000
@@ -2,6 +2,8 @@
 # Before `make install' is performed this script should be runnable with
 # `make test'. After `make install' it should work as `perl test.pl'
 
+# These test will only work on an english or german Windows!
+
 ######################### We start with some black magic to print on failure.
 
 BEGIN {
@@ -23,7 +25,9 @@
 # Win32API::File does an implicit "require Win32", but
 # the ../lib directory in @INC will no longer work once
 # we chdir() into the TEMP directory.
+
 use Win32;
+use File::Spec;
 use Carp;
 use Carp::Heavy;
 
@@ -37,19 +41,16 @@
 
 use strict qw(subs);
 
-$temp= $ENV{"TMP"};
-$temp= $ENV{"TEMP"}	unless -d $temp;
-$temp= "C:/Temp"	unless -d $temp;
-$temp= "."		unless -d $temp;
+$temp= File::Spec->tmpdir();
 $dir= "W32ApiF.tmp";
 
 $ENV{WINDIR} = $ENV{SYSTEMROOT} if not exists $ENV{WINDIR};
 
 chdir( $temp )
   or  die "# Can't cd to temp directory, $temp: $!\n";
-
+$tempdir = File::Spec->catdir($temp,$dir);
 if(  -d $dir  ) {
-    print "# deleting $temp\\$dir\\*\n" if glob "$dir/*";
+    print "# deleting ",File::Spec->catdir($temp,$dir,'*'),"\n" if glob "$dir/*";
 
     for (glob "$dir/*") {
 	chmod 0777, $_;
@@ -58,13 +59,12 @@
     rmdir $dir or die "Could not rmdir $dir: $!";
 }
 mkdir( $dir, 0777 )
-  or  die "# Can't create temp dir, $temp/$dir: $!\n";
-print "# chdir $temp\\$dir\n";
+  or  die "# Can't create temp dir, $tempdir: $!\n";
+print "# chdir $tempdir\n";
 chdir( $dir )
-  or  die "# Can't cd to my dir, $temp/$dir: $!\n";
-
+  or  die "# Can't cd to my dir, $tempdir: $!\n";
 $h1= createFile( "ReadOnly.txt", "r", { Attributes=>"r" } );
-$ok=  ! $h1  &&  fileLastError() =~ /not find the file?/i;
+$ok=  ! $h1  &&  Win32API::File::_fileLastError() == 2; # could not find the file
 $ok or print "# ","".fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 2
 if(  ! $ok  ) {   CloseHandle($h1);   unlink("ReadOnly.txt");   }
@@ -78,13 +78,13 @@
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 4
 
 $h2= createFile( "ReadOnly.txt", "rcn" );
-$ok= ! $h2  &&  fileLastError() =~ /file exists?/i;
+$ok= ! $h2  &&  Win32API::File::_fileLastError() == 80; # file exists
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 5
 if(  ! $ok  ) {   CloseHandle($h2);   }
 
 $h2= createFile( "ReadOnly.txt", "rwke" );
-$ok= ! $h2  &&  fileLastError() =~ /access is denied?/i;
+$ok= ! $h2  &&  Win32API::File::_fileLastError() == 5; # access is denied
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 6
 if(  ! $ok  ) {   CloseHandle($h2);   }
@@ -121,7 +121,7 @@
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 12
 
 $ok= ! ReadFile( $h2, $text, 80, $len, [] )
- &&  fileLastError() =~ /handle is invalid?/i;
+ &&  Win32API::File::_fileLastError() == 6; # handle is invalid
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 13
 
@@ -174,7 +174,7 @@
 }
 else {
     unlink("CanWrite.txt");
-    $ok= -e "CanWrite.txt" &&  $! =~ /permission denied/i;
+    $ok = -e "CanWrite.txt" &&  $! =~ /permission denied/i;
     $ok or print "# $!\n";
 }
 print $ok ? "" : "not ", "ok ", ++$test, "$skip\n"; # ok 22
@@ -184,37 +184,37 @@
 CloseHandle( $h1 );
 
 $ok= ! DeleteFile( "ReadOnly.txt" )
- &&  fileLastError() =~ /access is denied?/i;
+ &&  Win32API::File::_fileLastError() == 5; # access is denied
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 23
 
 $ok= ! CopyFile( "ReadOnly.txt", "CanWrite.txt", 1 )
- &&  fileLastError() =~ /file exists?/i;
+ &&  Win32API::File::_fileLastError() == 80; # file exists
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 24
 
 $ok= ! CopyFile( "CanWrite.txt", "ReadOnly.txt", 0 )
- &&  fileLastError() =~ /access is denied?/i;
+ &&  Win32API::File::_fileLastError() == 5; # access is denied
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 25
 
 $ok= ! MoveFile( "NoSuchFile", "NoSuchDest" )
- &&  fileLastError() =~ /not find the file/i;
+ &&  Win32API::File::_fileLastError() == 2; # not find the file
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 26
 
 $ok= ! MoveFileEx( "NoSuchFile", "NoSuchDest", 0 )
- &&  fileLastError() =~ /not find the file/i;
+ &&  Win32API::File::_fileLastError() == 2; # not find the file
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 27
 
 $ok= ! MoveFile( "ReadOnly.txt", "CanWrite.txt" )
- &&  fileLastError() =~ /file already exists?/i;
+ &&  Win32API::File::_fileLastError() == 183; # file already exists
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 28
 
 $ok= ! MoveFileEx( "ReadOnly.txt", "CanWrite.txt", 0 )
- &&  fileLastError() =~ /file already exists?/i;
+ &&  Win32API::File::_fileLastError() == 183; # file already exists
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 29
 
@@ -224,7 +224,7 @@
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 30
 
 $ok= ! MoveFileEx( "CanWrite.txt", "ReadOnly.cp", MOVEFILE_REPLACE_EXISTING )
- &&  fileLastError() =~ /access is denied?|cannot create/i;
+ &&  Win32API::File::_fileLastError() == 5; # access is denied
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 31
 
@@ -244,7 +244,7 @@
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 34
 
 $ok= ! DeleteFile( "Moved.cp" )
- &&  fileLastError() =~ /access is denied?/i;
+ &&  Win32API::File::_fileLastError() == 5; # access is denied
 $ok or print "# ",fileLastError(),"\n";
 print $ok ? "" : "not ", "ok ", ++$test, "\n";	# ok 35
 

@p5pRT
Copy link
Author

p5pRT commented Jun 25, 2007

From @rgs

On 23/06/07, Reini Urban via RT <perlbug-followup@​perl.org> wrote​:

Attached patch switches to error numbers to handle
various foreign languages.

Thanks, applied as #31458, removed an irrelevant comment as #31459.

@p5pRT
Copy link
Author

p5pRT commented Jun 25, 2007

@rgs - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant