Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
X-Injected-Via-Gmane: http://gmane.org/
To: cygwin@cygwin.com
From: Sam Steingold <sds@gnu.org>
Subject: mingw execv() bug bites cygwin gdb
Date: 20 Jul 2003 20:50:23 -0400
Organization: disorganization
Lines: 109
Message-ID: <uel0k3dps.fsf@gnu.org>
Reply-To: sds@gnu.org
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Complaints-To: usenet@main.gmane.org
X-Attribution: Sam
X-Disclaimer: You should not expect anyone to agree with me.
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50
Cc: mingw-users@lists.sourceforge.net


Compile the attached C program with
$ gcc -std=c99 -Wall -g argtest.c -o argtest-cygwin
$ gcc -std=c99 -Wall -g -mno-cygwin argtest.c -o argtest-mingw
and run it with
        $ args='"4 4" '"'5 5'"
        $ echo $args
        $ ./argtest-cygwin.exe "${args}" a
"4 4" '5 5'
 * argc=3
[./argtest-cygwin]
["4 4" '5 5']
[a]
 * argc=2
[./argtest-cygwin]
["4 4" '5 5']
 * argc=1
[./argtest-cygwin]
        $ ./argtest-mingw.exe  "${args}" a
 * argc=3
[d:\sds\c\argtest-mingw.exe]
["4 4" '5 5']
[a]
 * argc=4
[d:\sds\c\argtest-mingw.exe]
[4 4]
['5]
[5']
 * argc=4
[d:\sds\c\argtest-mingw.exe]
[4]
[4]
['5]
 * argc=3
[d:\sds\c\argtest-mingw.exe]
[4]
[4]
 * argc=2
[d:\sds\c\argtest-mingw.exe]
[4]
 * argc=1
[d:\sds\c\argtest-mingw.exe]

as you can see, mingw execv() splits argv()!!!
(the obvious workaround is to quote the argv args that contain spaces)

This appears to be a known mingw bug (at least since February 2002),
but somehow it is still there...

Now, the biggest trouble is that this bites cygwin gdb which passes
different arguments to cygwin and mingw executables:

(gdb) run arg 1 2 "3" "4 4" '5 5'
Starting program: /cygdrive/d/sds/c/argtest-mingw.exe arg 1 2 "3" "4 4" '5 5'
 * argc=8
[d:\sds\c\argtest-mingw.exe]
[arg]
[1]
[2]
[3]
[4 4]
['5]
[5']

(gdb) run arg 1 2 "3" "4 4" '5 5'
Starting program: /cygdrive/d/sds/c/argtest-cygwin.exe arg 1 2 "3" "4 4" '5 5'
 * argc=7
[/cygdrive/d/sds/c/argtest-cygwin]
[arg]
[1]
[2]
[3]
[4 4]
[5 5]



-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
When we write programs that "learn", it turns out we do and they don't.




--=-=-=
Content-Type: text/c
Content-Disposition: attachment; filename=argtest.c
Content-Description: C test program

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

int main (int argc, char *argv[]) {
  printf(" * argc=%d\n",argc);
  for (int i=0; i<argc; i++) printf("[%s]\n",argv[i]);
  if (argc>1) {
    argv[argc-1] = NULL;
    execv(argv[0],argv);
    perror(argv[0]);
    return 1;
  } else
    return 0;
}


--=-=-=
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
--=-=-=--

