Changeset 3214 for trunk


Ignore:
Timestamp:
Apr 25, 2007, 2:02:22 AM (18 years ago)
Author:
bird
Message:

/@executable_path. Fixes #153.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libc/src/kNIX/os2/fs-os2.c

    r2935 r3214  
    162162 * The special /@unixroot rewrite rule.
    163163 */
    164 static __LIBC_PATHREWRITE   gaRewriteRule =
    165 {
    166     __LIBC_PRWF_CASE_SENSITIVE | __LIBC_PRWF_TYPE_DIR,      "/@unixroot",  10, __libc_gszUnixRoot, 0
     164static __LIBC_PATHREWRITE   gUnixRootRewriteRule =
     165{
     166    __LIBC_PRWF_CASE_SENSITIVE | __LIBC_PRWF_TYPE_DIR,  "/@unixroot",  10, __libc_gszUnixRoot, 0
     167};
     168
     169/** The full path to the executable directory. */
     170char __libc_gszExecPath[CCHMAXPATH];
     171
     172/**
     173 * The special /@executable_path rewrite rule.
     174 */
     175static __LIBC_PATHREWRITE   gExecRewriteRule =
     176{
     177    __LIBC_PRWF_CASE_SENSITIVE | __LIBC_PRWF_TYPE_DIR,  "/@executable_path",  17, __libc_gszExecPath, 0
    167178};
    168179
     
    223234
    224235        /* Register rewrite rule. */
    225         gaRewriteRule.pszTo = "/";
    226         gaRewriteRule.cchTo = 1;
    227         if (__libc_PathRewriteAdd(&gaRewriteRule, 1))
     236        gUnixRootRewriteRule.pszTo = "/";
     237        gUnixRootRewriteRule.cchTo = 1;
     238        if (__libc_PathRewriteAdd(&gUnixRootRewriteRule, 1))
    228239            LIBCLOG_RETURN_INT(-1);
    229240    }
     
    251262
    252263            /* Register the rewrite rule. */
    253             gaRewriteRule.cchTo = cch;
    254             if (__libc_PathRewriteAdd(&gaRewriteRule, 1))
     264            gUnixRootRewriteRule.cchTo = cch;
     265            if (__libc_PathRewriteAdd(&gUnixRootRewriteRule, 1))
    255266                LIBCLOG_RETURN_INT(-1);
    256267        }
    257268    }
    258269
     270
     271    /*
     272     * Setup the the executable path rewrite rule.
     273     */
     274    PTIB pTib;
     275    PPIB pPib;
     276    DosGetInfoBlocks(&pTib, &pPib);
     277    rc = DosQueryModuleName(pPib->pib_hmte, sizeof(__libc_gszExecPath), &__libc_gszExecPath[0]);
     278    if (!rc)
     279    {
     280        char *psz = strchr(&__libc_gszExecPath[0], '\0');
     281        while (     psz > &__libc_gszExecPath[0]
     282               &&   *psz != '\\'
     283               &&   *psz != '/'
     284               &&   *psz != ':')
     285            psz--;
     286        *psz = '\0';
     287        gExecRewriteRule.cchTo = psz - &__libc_gszExecPath[0];
     288    }
     289    else
     290    {
     291        LIBC_ASSERTM_FAILED("DosQueryModuleName(exe) failed: hmte=%lx rc=%d\n", pPib->pib_hmte, rc);
     292        gExecRewriteRule.cchTo = 1;
     293        gExecRewriteRule.pszTo = "/";
     294    }
     295    if (__libc_PathRewriteAdd(&gExecRewriteRule, 1))
     296        LIBCLOG_RETURN_INT(-1);
    259297
    260298    /*
Note: See TracChangeset for help on using the changeset viewer.