Index: /branches/libc-0.6/src/emx/src/lib/sys/fs.c
===================================================================
--- /branches/libc-0.6/src/emx/src/lib/sys/fs.c	(revision 3213)
+++ /branches/libc-0.6/src/emx/src/lib/sys/fs.c	(revision 3214)
@@ -194,9 +194,19 @@
  * The special /@unixroot rewrite rule.
  */
-static __LIBC_PATHREWRITE   gaRewriteRule =
-{
-    __LIBC_PRWF_CASE_SENSITIVE | __LIBC_PRWF_TYPE_DIR,      "/@unixroot",  10, __libc_gszUnixRoot, 0
+static __LIBC_PATHREWRITE   gUnixRootRewriteRule =
+{
+    __LIBC_PRWF_CASE_SENSITIVE | __LIBC_PRWF_TYPE_DIR,  "/@unixroot",  10, __libc_gszUnixRoot, 0
 };
 
+/** The full path to the executable directory. */
+char __libc_gszExecPath[CCHMAXPATH];
+
+/**
+ * The special /@executable_path rewrite rule.
+ */
+static __LIBC_PATHREWRITE   gExecRewriteRule =
+{
+    __LIBC_PRWF_CASE_SENSITIVE | __LIBC_PRWF_TYPE_DIR,  "/@executable_path",  17, __libc_gszExecPath, 0
+};
 
 /** Array of pointers to fs info objects for all
@@ -278,7 +288,7 @@
 
         /* Register rewrite rule. */
-        gaRewriteRule.pszTo = "/";
-        gaRewriteRule.cchTo = 1;
-        if (__libc_PathRewriteAdd(&gaRewriteRule, 1))
+        gUnixRootRewriteRule.pszTo = "/";
+        gUnixRootRewriteRule.cchTo = 1;
+        if (__libc_PathRewriteAdd(&gUnixRootRewriteRule, 1))
             LIBCLOG_RETURN_INT(-1);
     }
@@ -308,6 +318,6 @@
 
                 /* Register the rewrite rule. */
-                gaRewriteRule.cchTo = cch;
-                if (__libc_PathRewriteAdd(&gaRewriteRule, 1))
+                gUnixRootRewriteRule.cchTo = cch;
+                if (__libc_PathRewriteAdd(&gUnixRootRewriteRule, 1))
                     LIBCLOG_RETURN_INT(-1);
             }
@@ -315,4 +325,31 @@
     }
 
+
+    /*
+     * Setup the the executable path rewrite rule.
+     */
+    PTIB pTib; 
+    PPIB pPib;
+    DosGetInfoBlocks(&pTib, &pPib);
+    rc = DosQueryModuleName(pPib->pib_hmte, sizeof(__libc_gszExecPath), &__libc_gszExecPath[0]);
+    if (!rc) 
+    {
+        char *psz = strchr(&__libc_gszExecPath[0], '\0');
+        while (     psz > &__libc_gszExecPath[0] 
+               &&   *psz != '\\'
+               &&   *psz != '/'
+               &&   *psz != ':')
+            psz--;
+        *psz = '\0';
+        gExecRewriteRule.cchTo = psz - &__libc_gszExecPath[0];
+    }
+    else
+    {
+        LIBC_ASSERTM_FAILED("DosQueryModuleName(exe) failed: hmte=%lx rc=%d\n", pPib->pib_hmte, rc);
+        gExecRewriteRule.cchTo = 1;
+        gExecRewriteRule.pszTo = "/";
+    }
+    if (__libc_PathRewriteAdd(&gExecRewriteRule, 1))
+        LIBCLOG_RETURN_INT(-1);
 
     /*
@@ -573,6 +610,6 @@
 void __libc_back_fsUpdateUnixRoot(const char *pszUnixRoot)
 {
-    gaRewriteRule.pszTo = "/";
-    gaRewriteRule.cchTo = 1;
+    gUnixRootRewriteRule.pszTo = "/";
+    gUnixRootRewriteRule.cchTo = 1;
 
     int cch = strlen(pszUnixRoot);
Index: /trunk/libc/src/kNIX/os2/fs-os2.c
===================================================================
--- /trunk/libc/src/kNIX/os2/fs-os2.c	(revision 3213)
+++ /trunk/libc/src/kNIX/os2/fs-os2.c	(revision 3214)
@@ -162,7 +162,18 @@
  * The special /@unixroot rewrite rule.
  */
-static __LIBC_PATHREWRITE   gaRewriteRule =
-{
-    __LIBC_PRWF_CASE_SENSITIVE | __LIBC_PRWF_TYPE_DIR,      "/@unixroot",  10, __libc_gszUnixRoot, 0
+static __LIBC_PATHREWRITE   gUnixRootRewriteRule =
+{
+    __LIBC_PRWF_CASE_SENSITIVE | __LIBC_PRWF_TYPE_DIR,  "/@unixroot",  10, __libc_gszUnixRoot, 0
+};
+
+/** The full path to the executable directory. */
+char __libc_gszExecPath[CCHMAXPATH];
+
+/**
+ * The special /@executable_path rewrite rule.
+ */
+static __LIBC_PATHREWRITE   gExecRewriteRule =
+{
+    __LIBC_PRWF_CASE_SENSITIVE | __LIBC_PRWF_TYPE_DIR,  "/@executable_path",  17, __libc_gszExecPath, 0
 };
 
@@ -223,7 +234,7 @@
 
         /* Register rewrite rule. */
-        gaRewriteRule.pszTo = "/";
-        gaRewriteRule.cchTo = 1;
-        if (__libc_PathRewriteAdd(&gaRewriteRule, 1))
+        gUnixRootRewriteRule.pszTo = "/";
+        gUnixRootRewriteRule.cchTo = 1;
+        if (__libc_PathRewriteAdd(&gUnixRootRewriteRule, 1))
             LIBCLOG_RETURN_INT(-1);
     }
@@ -251,10 +262,37 @@
 
             /* Register the rewrite rule. */
-            gaRewriteRule.cchTo = cch;
-            if (__libc_PathRewriteAdd(&gaRewriteRule, 1))
+            gUnixRootRewriteRule.cchTo = cch;
+            if (__libc_PathRewriteAdd(&gUnixRootRewriteRule, 1))
                 LIBCLOG_RETURN_INT(-1);
         }
     }
 
+
+    /*
+     * Setup the the executable path rewrite rule.
+     */
+    PTIB pTib; 
+    PPIB pPib;
+    DosGetInfoBlocks(&pTib, &pPib);
+    rc = DosQueryModuleName(pPib->pib_hmte, sizeof(__libc_gszExecPath), &__libc_gszExecPath[0]);
+    if (!rc) 
+    {
+        char *psz = strchr(&__libc_gszExecPath[0], '\0');
+        while (     psz > &__libc_gszExecPath[0] 
+               &&   *psz != '\\'
+               &&   *psz != '/'
+               &&   *psz != ':')
+            psz--;
+        *psz = '\0';
+        gExecRewriteRule.cchTo = psz - &__libc_gszExecPath[0];
+    }
+    else
+    {
+        LIBC_ASSERTM_FAILED("DosQueryModuleName(exe) failed: hmte=%lx rc=%d\n", pPib->pib_hmte, rc);
+        gExecRewriteRule.cchTo = 1;
+        gExecRewriteRule.pszTo = "/";
+    }
+    if (__libc_PathRewriteAdd(&gExecRewriteRule, 1))
+        LIBCLOG_RETURN_INT(-1);
 
     /*
