Changeset 944 in kBuild
- Timestamp:
- May 26, 2007 11:43:35 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmakenew/kbuild.c
r939 r944 38 38 #ifdef WINDOWS32 39 39 # include "pathstuff.h" 40 # include <Windows.h> 40 41 #endif 41 42 … … 59 60 *******************************************************************************/ 60 61 /** The argv[0] passed to main. */ 61 static const char *g_ argv0 = "";62 static const char *g_pszExeName; 62 63 /** The initial working directory. */ 63 static char *g_pszInitialCwd = ".";64 static char *g_pszInitialCwd; 64 65 65 66 … … 72 73 void init_kbuild(int argc, char **argv) 73 74 { 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 */ 77 81 #ifdef WINDOWS32 78 if (getcwd_fs(sz Cwd, GET_PATH_MAX) != 0)82 if (getcwd_fs(szTmp, GET_PATH_MAX) != 0) 79 83 #else 80 if (getcwd(sz Cwd, GET_PATH_MAX) != 0)81 #endif 82 g_pszInitialCwd = xstrdup(sz Cwd);84 if (getcwd(szTmp, GET_PATH_MAX) != 0) 85 #endif 86 g_pszInitialCwd = xstrdup(szTmp); 83 87 else 84 88 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); 85 135 } 86 136 … … 153 203 #else 154 204 /* $(abspath $(dir $(ARGV0)).) */ 155 size_t cch = strlen(g_ argv0);205 size_t cch = strlen(g_pszExeName); 156 206 char *pszTmp2 = alloca(cch + sizeof(".")); 157 207 char *pszSep = pszTmp2 + cch - 1; 158 memcpy(pszTmp2, g_ argv0, cch);208 memcpy(pszTmp2, g_pszExeName, cch); 159 209 #ifdef HAVE_DOS_PATHS 160 210 while (pszSep >= pszTmp2 && *pszSep != '/' && *pszSep != '\\' && *pszSep != ':')
Note:
See TracChangeset
for help on using the changeset viewer.