aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/lib
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2004-12-09 21:28:32 +0000
committerChristopher Faylor <me@cgf.cx>2004-12-09 21:28:32 +0000
commitfc2eba361ccc55ad5efb2a4cb804cfbb348d8a90 (patch)
tree1bcd435c646d4ea98fd0c05b64d80fd94e5f5b2a /winsup/cygwin/lib
parent23b9802aa05df57f58239b6876c65bcf6785e23f (diff)
downloadnewlib-fc2eba361ccc55ad5efb2a4cb804cfbb348d8a90.zip
newlib-fc2eba361ccc55ad5efb2a4cb804cfbb348d8a90.tar.gz
newlib-fc2eba361ccc55ad5efb2a4cb804cfbb348d8a90.tar.bz2
* lib/libcmain.c (main): Properly deal with quoted first argument.
Diffstat (limited to 'winsup/cygwin/lib')
-rw-r--r--winsup/cygwin/lib/libcmain.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/winsup/cygwin/lib/libcmain.c b/winsup/cygwin/lib/libcmain.c
index 13cc34c..b0c0119 100644
--- a/winsup/cygwin/lib/libcmain.c
+++ b/winsup/cygwin/lib/libcmain.c
@@ -9,26 +9,35 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include <windows.h>
+#include <string.h>
+
+#define SP " \t\n"
/* Allow apps which don't have a main work, as long as they define WinMain */
int
main ()
{
- HMODULE x = GetModuleHandleA(0);
- char *s = GetCommandLineA ();
+ HMODULE x = GetModuleHandle (0);
+ char *s = GetCommandLine ();
STARTUPINFO si;
+ char *nexts;
+
+ s += strspn (s, SP);
+
+ if (*s != '"')
+ nexts = strpbrk (s, SP);
+ else
+ while ((nexts = strchr (s + 1, '"')) != NULL && nexts[-1] == '\\')
+ s = nexts;
- /* GetCommandLineA returns the entire command line including the
- program name, but WinMain is defined to accept the command
- line without the program name. */
- while (*s != ' ' && *s != '\0')
- ++s;
- while (*s == ' ')
- ++s;
+ if (!nexts)
+ nexts = strchr (s, '\0');
+ else
+ nexts += strspn (nexts + 1, SP);
GetStartupInfo (&si);
- return WinMain (x, 0, s,
+ return WinMain (x, 0, nexts,
((si.dwFlags & STARTF_USESHOWWINDOW) != 0
? si.wShowWindow
: SW_SHOWNORMAL));