This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: CreateProcess() - executed program gets different argument depending if it's compiled with gcc (cygwin) or cl (VS)?

> As you can see dumpargs_gcc receives "\\foo.cxx" and dumpargs_cl receives "\\\foo.cxx".

Interesting.  I am confused, too.

(1) Native-only parameter passing:

  execv(PROG, ARGV)  ->  MSVCRT  ->  line = M(ARGV)  ->  CreateProcess( PROG, line, .. )  -> 

           MSVCRT ->  CommandLineToArgvW( line ) -> argv, argc = M'( line )  ->  int main( int argc, char *argv[] )

(2) POSIX compatibility wrapper (Cygwin):

  execv(PROG, ARGV)  ->  Cygwin DLL  ->  prog = W(PROG), line = C(ARGV)  ->  CreateProcess( prog, line, .. )

       (a) PROG is a native program:

              ->  MSVCRT  ->  CommandLineToArgvW( line )  -> argc, argv = M'( line )  -> int main( int argc, char *argv[] )

       (b) PROG is another Cygwin-linked program:

              ->  Cygwin stub (crt0?)  -> argc, argv = C'( line ) ->  int main( int argc, char *argv[] )

Thanks to your createprocess.c/dumpargs.c pair, I could figure the existing Cygwin's parsing without looking into its source code.  It turned to ignore the escaping power of a bare (unquoted) backslash when it was followed by a double quote, which is against both MSVC and Bash rules.

Here is my understanding of expansion features of Win32 (M), Bash (B) and Cygwin (C) shown as a diagram, where "special character" means a dollar sign [$], a double quote ["], another backslash [\], backquote [`] or a newline, as explained in section 2.2.3 Double-Quotes of the Open Group's XCU document.

        Bare backslashes   Bare backslashes     Quoted backslashes     Quoted backslashes
        not followed by a  followed by a        not followed by a      followed by a
        double quote       double quote         special character      special character

 MSVC   regular            protecting           regular                regular
 Bash   protecting         protecting           regular                protecting

 Cygwin regular            protecting           regular                protecting

So I guess the confusion remains as to why (a) C != M and (b) C != B.

Attachment: createprocess.c
Description: Text document

Attachment: createprocess_cl.txt
Description: Text document

Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]