VirtualBox

Changeset 927 in kBuild for trunk/src/gmakenew


Ignore:
Timestamp:
May 25, 2007 9:30:31 PM (18 years ago)
Author:
bird
Message:

Fixed some PATH_KBUILD_BIN mess + the init warnings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmakenew/kbuild.c

    r917 r927  
    5757/** The argv[0] passed to main. */
    5858static const char *g_argv0 = "";
     59/** The initial working directory. */
     60static const char *g_pszInitialCwd = ".";
    5961
    6062
     
    6769void init_kbuild(int argc, char **argv)
    6870{
     71    PATH_VAR(szCwd);
     72
    6973    g_argv0 = argv[0];
     74#ifdef WINDOWS32
     75    if (getcwd_fs(szCwd, GET_PATH_MAX) != 0)
     76#else
     77    if (getcwd(szCwd, GET_PATH_MAX) != 0)
     78#endif
     79        g_pszInitialCwd = xstrdup(szCwd);
     80    else
     81        fatal(NILF, _("getcwd failed"));
     82}
     83
     84
     85/**
     86 * Wrapper that ensures correct starting_directory.
     87 */
     88static char *my_abspath(const char *pszIn, char *pszOut)
     89{
     90    char *pszSaved, *pszRet;
     91
     92    pszSaved = starting_directory;
     93    starting_directory = g_pszInitialCwd;
     94    pszRet = abspath(pszIn, pszOut);
     95    starting_directory = pszSaved;
     96
     97    return pszRet;
    7098}
    7199
     
    84112        const char *pszEnvVar = getenv("PATH_KBUILD");
    85113        if (    !pszEnvVar
    86             ||  !abspath(pszEnvVar, szTmpPath))
     114            ||  !my_abspath(pszEnvVar, szTmpPath))
    87115        {
    88116#ifdef PATH_KBUILD
     
    93121            char *pszTmp2 = alloca(cch + sizeof("/../.."));
    94122            strcat(strcpy(pszTmp2, get_path_kbuild_bin()), "/../..");
    95             if (!abspath(pszTmp2, szTmpPath))
     123            if (!my_abspath(pszTmp2, szTmpPath))
    96124                fatal(NILF, _("failed to determin PATH_KBUILD"));
    97125#endif
     
    116144        const char *pszEnvVar = getenv("PATH_KBUILD_BIN");
    117145        if (    !pszEnvVar
    118             ||  !abspath(pszEnvVar, szTmpPath))
     146            ||  !my_abspath(pszEnvVar, szTmpPath))
    119147        {
    120148#ifdef PATH_KBUILD
    121149            return s_pszPath = PATH_KBUILD_BIN;
    122150#else
    123             /* $(abspath $(ARGV0)/../../..) - the filename shouldn't cause trouble... */
     151            /* $(abspath $(dir $(ARGV0)).) */
    124152            size_t cch = strlen(g_argv0);
    125             char *pszTmp2 = alloca(cch + sizeof("/../../.."));
    126             strcat(strcpy(pszTmp2, g_argv0), "/../../..");
    127             if (!abspath(pszTmp2, szTmpPath))
    128                 fatal(NILF, _("failed to determin PATH_KBUILD_BIN"));
     153            char *pszTmp2 = alloca(cch + sizeof("."));
     154            char *pszSep = pszTmp2 + cch - 1;
     155            memcpy(pszTmp2, g_argv0, cch);
     156#ifdef HAVE_DOS_PATHS
     157            while (pszSep >= pszTmp2 && *pszSep != '/' && *pszSep != '\\' && pszSep != ':')
     158#else
     159            while (pszSep >= pszTmp2 && *pszSep != '/')
     160#endif
     161                pszSep--;
     162            if (pszSep >= pszTmp2)
     163              strcpy(pszSep + 1, ".");
     164            else
     165              strcpy(pszTmp2, ".");
     166
     167            if (!my_abspath(pszTmp2, szTmpPath))
     168                fatal(NILF, _("failed to determin PATH_KBUILD_BIN (pszTmp2=%s szTmpPath=%s)"), pszTmp2, szTmpPath);
    129169#endif
    130170        }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette