VirtualBox

Changeset 944 in kBuild


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

darwin doesn't give me the path in argv[0] if kmk was found in that PATH. So, query the exec name using platform specific interfaces when possible.

File:
1 edited

Legend:

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

    r939 r944  
    3838#ifdef WINDOWS32
    3939# include "pathstuff.h"
     40# include <Windows.h>
    4041#endif
    4142
     
    5960*******************************************************************************/
    6061/** The argv[0] passed to main. */
    61 static const char *g_argv0 = "";
     62static const char *g_pszExeName;
    6263/** The initial working directory. */
    63 static char *g_pszInitialCwd = ".";
     64static char *g_pszInitialCwd;
    6465
    6566
     
    7273void init_kbuild(int argc, char **argv)
    7374{
    74     PATH_VAR(szCwd);
    75 
    76     g_argv0 = argv[0];
     75    int rc;
     76    PATH_VAR(szTmp);
     77
     78    /*
     79     * Get the initial cwd for use in my_abspath.
     80     */
    7781#ifdef WINDOWS32
    78     if (getcwd_fs(szCwd, GET_PATH_MAX) != 0)
     82    if (getcwd_fs(szTmp, GET_PATH_MAX) != 0)
    7983#else
    80     if (getcwd(szCwd, GET_PATH_MAX) != 0)
    81 #endif
    82         g_pszInitialCwd = xstrdup(szCwd);
     84    if (getcwd(szTmp, GET_PATH_MAX) != 0)
     85#endif
     86        g_pszInitialCwd = xstrdup(szTmp);
    8387    else
    8488        fatal(NILF, _("getcwd failed"));
     89
     90    /*
     91     * Determin the executable name.
     92     */
     93    rc = -1;
     94#if defined(__DARWIN__)
     95    {
     96        const char *pszImageName = _dyld_get_image_name(0);
     97        if (pszImageName)
     98        {
     99            size_t cchImageName = strlen(pszImageName);
     100            if (cchImageName < GET_PATH_MAX)
     101            {
     102                memcpy(szTmp, pszImageName, cchImageName + 1);
     103                rc = 0;
     104            }
     105        }
     106    }
     107
     108#elif defined(__FreeBSD__)
     109    rc = readlink("/proc/curproc/file", szTmp, GET_PATH_MAX - 1);
     110    if (rc < 0 || rc == GET_PATH_MAX - 1)
     111        rc = -1;
     112    else
     113        szTmp[rc] == '\0';
     114
     115#elif defined(__LINUX__) /** @todo find proper define... */
     116    rc = readlink("/proc/self/exe", szTmp, GET_PATH_MAX - 1);
     117    if (rc < 0 || rc == GET_PATH_MAX - 1)
     118        rc = -1;
     119    else
     120        szTmp[rc] == '\0';
     121
     122#elif defined(__OS2__)
     123     _execname(g_szrtProgramPath, sizeof(g_szrtProgramPath));
     124     rc = 0;
     125
     126#elif defined(WINDOWS32)
     127    if (GetModuleFileName(GetModuleHandle(NULL), szTmp, GET_PATH_MAX))
     128        rc = 0;
     129
     130#endif
     131    if (rc < 0)
     132        g_pszExeName = argv[0];
     133    else
     134        g_pszExeName = xstrdup(szTmp);
    85135}
    86136
     
    153203#else
    154204            /* $(abspath $(dir $(ARGV0)).) */
    155             size_t cch = strlen(g_argv0);
     205            size_t cch = strlen(g_pszExeName);
    156206            char *pszTmp2 = alloca(cch + sizeof("."));
    157207            char *pszSep = pszTmp2 + cch - 1;
    158             memcpy(pszTmp2, g_argv0, cch);
     208            memcpy(pszTmp2, g_pszExeName, cch);
    159209#ifdef HAVE_DOS_PATHS
    160210            while (pszSep >= pszTmp2 && *pszSep != '/' && *pszSep != '\\' && *pszSep != ':')
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