But, it would be 'correcting' for a bug ... in the CRT
Yeah ... and I guess that if it were to be 'corrected' in perl (as I was recommending), there's always the chance that someone will object because we're no longer following Windows CRT behaviour.
Maybe perl should warn about this whenever
$file =~ /^"/ && $file !~ /[^"]/ && $^O =~ /MSWin32/i
(which, I think, are the pertinent conditions) but I don't think I'll take that up with the powers that be.
Cheers, Rob | [reply] [d/l] |
Maybe perl should warn about this
The more I think about it, the less I like the idea of a warning for what is just platform specific behaviour.
There's that "non-portable" warning about integers > 2**32 that pops up on 64-bit platforms; it just bugs me.
I think the simplest solution is the best here: just add a note about it to the stat docs.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
| [reply] |
I agree that the 'problem' has nothing to do whith perl. It makes sense to consider double quotes around a windows filename as required if the filename contains whitespace and optional otherwise. From this view, the dir command followed by two double quotes should display the same thing as the dir command without them - the current directory. This logic requires other system functions to also treat the null file name as the current directory. | [reply] |
You are mixing command line parsing in command.com / cmd.exe and the Windows-APIs.
Unlike in Unix, command line parsing is the job of the invoked program (and not that of the shell) on Windows, this typically happens in the C RTL. The command interpreters themself also parse their input, but only to find the executable or build-in command and to handle redirections. The build-in commands (dir, cd, ...) must also parse their argument string, probably using the same or very similar routines.
After that parsing has happened, quotes and escape characters are gone, and the program or build-in command has a list of (unescaped) arguments, some of them are passed to API functions. The API functions do not remove quotes:
X:\>dir 979536.exe
Volume in drive X is RAMDISK
Volume Serial Number is 065B-0000
Directory of X:\
05.07.2012 22:04 121.535 979536.exe
1 File(s) 121.535 bytes
0 Dir(s) 129.867.776 bytes free
X:\>dir "979536.exe"
Volume in drive X is RAMDISK
Volume Serial Number is 065B-0000
Directory of X:\
05.07.2012 22:04 121.535 979536.exe
1 File(s) 121.535 bytes
0 Dir(s) 129.867.776 bytes free
X:\>perl -Mautodie -e "open $f,'979536.exe'"
X:\>perl -Mautodie -e "open $f,chr(34).'979536.exe'.chr(34)"
Can't open($fh, '"979536.exe"'): Invalid argument at -e line 1
X:\>type openfail.c
#include <stdio.h>
#include <errno.h>
int main(int argc, char ** argv)
{
FILE * f;
if ((f=fopen("979536.exe","r"))==NULL) {
perror("open without quotes");
} else {
fclose(f);
}
if ((f=fopen("\"979536.exe\"","r"))==NULL) {
perror("open with quotes");
} else {
fclose(f);
}
return 0;
}
X:\>gcc -Wall -pedantic -o openfail.exe openfail.c
X:\>.\openfail.exe
open with quotes: Invalid argument
X:\>
Alexander
--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
| [reply] [d/l] |