Index: branches/libc-0.6/src/emx/src/lib/sys/__init.c
===================================================================
--- branches/libc-0.6/src/emx/src/lib/sys/__init.c	(revision 2987)
+++ branches/libc-0.6/src/emx/src/lib/sys/__init.c	(revision 2990)
@@ -45,4 +45,5 @@
 *******************************************************************************/
 static int parse_args(const char *src, char **argv, char *pool);
+static int verify_end_of_single_quote(const char *src);
 
 
@@ -79,7 +80,8 @@
 static int parse_args(const char *src, char **argv, char *pool)
 {
-    int bs, quote;
+    int   quote;
+    char  flags; 
     char *flag_ptr;
-    int   arg_size;
+    int   arg_size, arg_pos;
 
     argc = 0; arg_size = 0;
@@ -101,40 +103,84 @@
         if (*src == 0)
             break;
-        flag_ptr = pool;
-        PUTC((char)_ARG_NONZERO);
+        if (!pool)
+        {
+            flags = _ARG_NONZERO;
+            flag_ptr = &flags;
+            arg_size++;
+        }
+        else
+        {
+            flag_ptr = pool;
+            PUTC((char)_ARG_NONZERO);
+        }
+        arg_pos = arg_size;
         PUTV;
-        bs = 0; quote = 0;
+        quote = 0;
         for (;;)
         {
-            if (!quote ? (*src == '"' || *src == '\'') : *src == quote)
+            /* End quote. */
+            if (*src == quote && quote)
+                quote = 0;
+            /* Start of double quote. */
+            else if (!quote && *src == '"')
             {
-                while (bs >= 2)
+                quote = '"';
+                *flag_ptr |= _ARG_DQUOTE;
+            }
+            /* 
+             * Only permit the single quote to be used at the start of an argument or
+             * within an already quoted one. This restriction is necessary to support
+             * unquoted filenames containing the single quote char. 
+             */
+            else if (   !quote && *src == '\'' 
+                     && (   arg_pos == arg_size 
+                         || (*flag_ptr & _ARG_DQUOTE)))
+            {
+                quote = '\'';
+                *flag_ptr |= _ARG_DQUOTE;
+            }
+            /* 
+             * The escape character. This is truly magic/weird. 
+             * It doesn't escape anything unless it's in front of a 
+             * double quote character. EMX weirdness...
+             * (Ok, not escaping more than necessary is ok when using \ as path 
+             * separator, but why weird interpretation of \\\\"asdf"?
+             */
+            else if (*src == '\\' && quote != '\'')
+            {
+                int cSlashes = 0;
+                do
                 {
-                    PUTC('\\');
-                    bs -= 2;
+                    cSlashes++;
+                    src++;
+                } while (*src == '\\');
+
+                if (*src == '"')
+                {
+                    /* Treat it is as escapes. */
+                    while (cSlashes >= 2)
+                    {
+                        PUTC('\\');
+                        cSlashes -= 2;
+                    }
+                    if (cSlashes & 1)
+                        PUTC(*src);
+                    else
+                        src--;
                 }
-                if (bs & 1)
-                    PUTC(*src);
                 else
                 {
-                    quote = quote ? 0 : *src;
-                    if (flag_ptr != NULL)
-                        *flag_ptr |= _ARG_DQUOTE;
+                    /* unmodified, no escaping. */
+                    while (cSlashes-- > 0)
+                        PUTC('\\');
+                    src--;
                 }
-                bs = 0;
             }
-            else if (*src == '\\')
-                ++bs;
+            /* Check for end of argument. */
+            else if (*src == 0 || (WHITE(*src) && !quote))
+                break;
+            /* Normal character. */
             else
-            {
-                while (bs != 0)
-                {
-                    PUTC('\\');
-                    --bs;
-                }
-                if (*src == 0 || (WHITE(*src) && !quote))
-                    break;
                 PUTC(*src);
-            }
             ++src;
         }
@@ -143,4 +189,15 @@
     return arg_size;
 }
+
+
+/**
+ * This is a hack to prevent us from messing up filenames that 
+ * include a \' character. 
+ *  
+ * @param src
+ * 
+ * @return int
+ */
+static int verify_end_of_single_quote(const char *src);
 
 
