Changeset 3289 for branches/libc-0.6


Ignore:
Timestamp:
May 2, 2007, 11:43:02 PM (18 years ago)
Author:
bird
Message:

Implemented /@system_root, /@system_drive and /@tmpdir default rewrite rules. Fixes #160.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/libc-0.6/src/emx/src/lib/sys/fs.c

    r3214 r3289  
    201201/** The full path to the executable directory. */
    202202char __libc_gszExecPath[CCHMAXPATH];
    203 
    204 /**
    205  * The special /@executable_path rewrite rule.
    206  */
    207 static __LIBC_PATHREWRITE   gExecRewriteRule =
    208 {
    209     __LIBC_PRWF_CASE_SENSITIVE | __LIBC_PRWF_TYPE_DIR,  "/@executable_path",  17, __libc_gszExecPath, 0
     203/** The system drive. */
     204char __libc_gszSystemDrive[4] = "C:";
     205/** The full path to the host system root directory. */
     206char __libc_gszSystemRoot[8] = "C:/OS2";
     207/** The path to the default tmp directory (might be a winding path). */
     208char __libc_gszTmpDir[CCHMAXPATH] = "C:/TEMP";
     209
     210/**
     211 * The misc rewrite rules.
     212 */
     213static __LIBC_PATHREWRITE   gaMiscRewriteRules[4] =
     214{
     215    { __LIBC_PRWF_CASE_SENSITIVE | __LIBC_PRWF_TYPE_DIR,  "/@executable_path",  17, __libc_gszExecPath, 0 },
     216    { __LIBC_PRWF_CASE_SENSITIVE | __LIBC_PRWF_TYPE_DIR,  "/@system_drive",     14, __libc_gszSystemDrive, 2 },
     217    { __LIBC_PRWF_CASE_SENSITIVE | __LIBC_PRWF_TYPE_DIR,  "/@system_root",      13, __libc_gszSystemRoot, 6 },
     218    { __LIBC_PRWF_CASE_SENSITIVE | __LIBC_PRWF_TYPE_DIR,  "/@tmpdir",            8, __libc_gszTmpDir, 7 }
    210219};
    211220
     
    325334    }
    326335
    327 
    328336    /*
    329337     * Setup the the executable path rewrite rule.
     
    342350            psz--;
    343351        *psz = '\0';
    344         gExecRewriteRule.cchTo = psz - &__libc_gszExecPath[0];
     352        gaMiscRewriteRules[0].cchTo = psz - &__libc_gszExecPath[0];
    345353    }
    346354    else
    347355    {
    348356        LIBC_ASSERTM_FAILED("DosQueryModuleName(exe) failed: hmte=%lx rc=%d\n", pPib->pib_hmte, rc);
    349         gExecRewriteRule.cchTo = 1;
    350         gExecRewriteRule.pszTo = "/";
    351     }
    352     if (__libc_PathRewriteAdd(&gExecRewriteRule, 1))
    353         LIBCLOG_RETURN_INT(-1);
     357        gaMiscRewriteRules[0].cchTo = 1;
     358        gaMiscRewriteRules[0].pszTo = "/";
     359    }
     360
     361    /*
     362     * Setup the the (host) system root path and system root drive rewrite rules.
     363     */
     364    ULONG ulBootDrive;
     365    if (DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive, sizeof(ulBootDrive)))
     366        ulBootDrive = 'C' - 'A' - 1; /* A = 1 */
     367    __libc_gszTmpDir[0] = __libc_gszSystemRoot[0] = __libc_gszSystemDrive[0]
     368        = (char)ulBootDrive + 'A' - 1;
     369
     370    /*
     371     * Setup the the temp path rewrite rule.
     372     */
     373    size_t cchTmp = 0;
     374    char *pszTmp = getenv("TMP");
     375    if (pszTmp)
     376        cchTmp = strlen(pszTmp);
     377    if (!pszTmp || cchTmp >= sizeof(__libc_gszTmpDir) - 1)
     378    {
     379        pszTmp = getenv("TEMP");
     380        if (pszTmp)
     381            cchTmp = strlen(pszTmp);
     382        if (!pszTmp || cchTmp >= sizeof(__libc_gszTmpDir) - 1)
     383        {
     384            pszTmp = getenv("TMPDIR");
     385            if (pszTmp)
     386                cchTmp = strlen(pszTmp);
     387        }
     388    }
     389    if (pszTmp && cchTmp <= sizeof(__libc_gszTmpDir) - 1)
     390    {
     391        /** @todo cleanup the thing so it won't get rejected! */
     392        memcpy(__libc_gszTmpDir, pszTmp, cchTmp + 1);
     393        gaMiscRewriteRules[3].cchTo = cchTmp;
     394    }
     395
     396    /*
     397     * Finally register the rules.
     398     */
     399/** @todo Make static rules from these and only update the replacement value and length. */
     400    if (__libc_PathRewriteAdd(&gaMiscRewriteRules[0], 4))
     401    {
     402        /* tmp rewrite rule is busted by the env.var., use the default. */
     403        memcpy(__libc_gszTmpDir, "C:/TEMP", sizeof("C:/TEMP"));
     404        gaMiscRewriteRules[3].cchTo = sizeof("C:/TEMP") - 1;
     405        if (__libc_PathRewriteAdd(&gaMiscRewriteRules[0], 4))
     406            LIBCLOG_RETURN_INT(-1);
     407    }
     408
    354409
    355410    /*
     
    381436    }
    382437    DosFreeModule(hmod);
    383 
    384438    LIBCLOG_RETURN_INT(0);
    385439}
Note: See TracChangeset for help on using the changeset viewer.