X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:mime-version:date:message-id:subject:from:to
	:content-type; q=dns; s=default; b=EIRg4hvj+mTIpUeFi9ktCLTkOoNFQ
	waVjtHq78HIdJ6dVxpxXoRIIfBwhJ+vqFvryTNuD5RW2iiz1J6zs0KQNC1Qilmoa
	nkgzg1IS3kccQPjkOIR+T25ozJTlpZkV0UM6+5C74pAKo1nUi2YB2h6Rq7VOSElA
	52MGGwewtdIHRo=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:mime-version:date:message-id:subject:from:to
	:content-type; s=default; bh=djLTxybtEuwtar3L3JaggYGGWjU=; b=kcq
	kNiaKgsNSyR1P27rDse8ud8LB6v0evJego9kqtzl4E8CLsj1UmmG4rb8GQYfs2aF
	nZYpjVPbp1J7mfiJk40vrUAUWksArSo7G6rAGGAJ6vXY2Rs4URIARAmULqbBBZDI
	M9T0CgbMR1HJtFZ+C0svQhpE2u217H4wxs8EqClE=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=4.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,KAM_FROM_URIBL_PCCC,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2
X-HELO: mail-lb0-f177.google.com
MIME-Version: 1.0
X-Received: by 10.112.185.101 with SMTP id fb5mr5838211lbc.12.1424923951978; Wed, 25 Feb 2015 20:12:31 -0800 (PST)
Date: Wed, 25 Feb 2015 23:12:31 -0500
Message-ID: <CAKVG1_rma3GmO9JDbB0qCE_m0wwYm3vT5+QbxYhchrMLrkORDQ@mail.gmail.com>
Subject: Why does CYGWIN double the backslash in execvp()?
From: A L <al20878@gmail.com>
To: cygwin@cygwin.com
Content-Type: text/plain; charset=ISO-8859-1

Hello,

Here's code that (if BUG is defined) does not work because it looks
like Cygwin doubles the backslash in args[2] when that gets passed to
CMD.  If I add a trailing period (#undef BUG), the preceding backslash
does not get doubled, the command runs as it is supposed to.
Why there's an additional backslash in the first case?  Should not
args be passed "as is"?
Running under strace confirms the extraneous addition.
---
#include <stdio.h>
#include <unistd.h>

#define BUG

int main()
{
  const char* args[4];
  char** xargs;
  args[0] = "/cygdrive/c/windows/system32/cmd.exe";
  args[1] = "/c";
#ifdef BUG
  args[2] = "DIR C:\\";
#else
  args[2] = "DIR C:\\.";
#endif
  args[3] = 0;
  printf("Command = \"%s %s %s\"\n", args[0], args[1], args[2]);
  xargs = (char**) &args;
  execvp(args[0], xargs);
  return 0;
}
---
Compare:

 1834   22106 [main] a 7152 child_info_spawn::worker: pid 7152,
prog_arg /cygdrive/c/windows/system32/cmd.exe, cmd line
C:\windows\system32\cmd.exe /c "DIR C:\\")


 1595   19614 [main] a 4356 child_info_spawn::worker: pid 4356,
prog_arg /cygdrive/c/windows/system32/cmd.exe, cmd line
C:\windows\system32\cmd.exe /c "DIR C:\.")

Maybe I'm doing something wrong, any ideas?

Thanks,
AL

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

