From dfc991a98a22c8f440345ced7a906d90edf410dc Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Wed, 5 Dec 2007 19:35:00 +0100 Subject: [PATCH] Clean up compat/mingw.c. The PATH related functions are now static and can lose the mingw_ prefix. path_lookup() no longer looks in the current directory, and it will now actually return NULL. Previously, it returned the input program name as a fallback. Signed-off-by: Johannes Sixt --- compat/mingw.c | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index e74f148b27..d32722ee26 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1,4 +1,3 @@ -#include #include "../git-compat-util.h" #include "../strbuf.h" @@ -176,15 +175,15 @@ int mingw_fstat(int fd, struct mingw_stat *buf) return -1; } -unsigned int sleep (unsigned int __seconds) +unsigned int sleep (unsigned int seconds) { - Sleep(__seconds*1000); + Sleep(seconds*1000); return 0; } -int mkstemp (char *__template) +int mkstemp(char *template) { - char *filename = mktemp(__template); + char *filename = mktemp(template); if (filename == NULL) return -1; return open(filename, O_RDWR | O_CREAT, 0600); @@ -314,8 +313,6 @@ repeat: return 0; } -#include - struct tm *gmtime_r(const time_t *timep, struct tm *result) { memcpy(result, gmtime(timep), sizeof(struct tm)); @@ -441,7 +438,7 @@ static const char *parse_interpreter(const char *cmd) /* * Splits the PATH into parts. */ -static char **mingw_get_path_split(void) +static char **get_path_split(void) { char *p, **path, *envpath = getenv("PATH"); int i, n = 0; @@ -477,7 +474,7 @@ static char **mingw_get_path_split(void) return path; } -static void mingw_free_path_split(char **path) +static void free_path_split(char **path) { if (!path) return; @@ -509,9 +506,8 @@ static char *lookup_prog(const char *dir, const char *cmd, int isexe, int exe_on * Determines the absolute path of cmd using the the split path in path. * If cmd contains a slash or backslash, no lookup is performed. */ -static char *mingw_path_lookup(const char *cmd, char **path, int exe_only) +static char *path_lookup(const char *cmd, char **path, int exe_only) { - char **p = path; char *prog = NULL; int len = strlen(cmd); int isexe = len >= 4 && !strcasecmp(cmd+len-4, ".exe"); @@ -519,14 +515,9 @@ static char *mingw_path_lookup(const char *cmd, char **path, int exe_only) if (strchr(cmd, '/') || strchr(cmd, '\\')) prog = xstrdup(cmd); - while (!prog && *p) { - prog = lookup_prog(*p++, cmd, isexe, exe_only); - } - if (!prog) { - prog = lookup_prog(".", cmd, isexe, exe_only); - if (!prog) - prog = xstrdup(cmd); - } + while (!prog && *path) + prog = lookup_prog(*path++, cmd, isexe, exe_only); + return prog; } @@ -630,8 +621,8 @@ static pid_t mingw_spawnve(const char *cmd, const char **argv, char **env, pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env) { pid_t pid; - char **path = mingw_get_path_split(); - char *prog = mingw_path_lookup(cmd, path, 0); + char **path = get_path_split(); + char *prog = path_lookup(cmd, path, 0); if (!prog) { errno = ENOENT; @@ -642,7 +633,7 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env) if (interpr) { const char *argv0 = argv[0]; - char *iprog = mingw_path_lookup(interpr, path, 1); + char *iprog = path_lookup(interpr, path, 1); argv[0] = prog; if (!iprog) { errno = ENOENT; @@ -658,7 +649,7 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env) pid = mingw_spawnve(prog, argv, env, 0); free(prog); } - mingw_free_path_split(path); + free_path_split(path); return pid; } @@ -671,8 +662,8 @@ static int try_shell_exec(const char *cmd, char *const *argv, char **env) if (!interpr) return 0; - path = mingw_get_path_split(); - prog = mingw_path_lookup(interpr, path, 1); + path = get_path_split(); + prog = path_lookup(interpr, path, 1); if (prog) { int argc = 0; const char **argv2; @@ -691,7 +682,7 @@ static int try_shell_exec(const char *cmd, char *const *argv, char **env) free(prog); free(argv2); } - mingw_free_path_split(path); + free_path_split(path); return pid; } @@ -712,8 +703,8 @@ static void mingw_execve(const char *cmd, char *const *argv, char *const *env) void mingw_execvp(const char *cmd, char *const *argv) { - char **path = mingw_get_path_split(); - char *prog = mingw_path_lookup(cmd, path, 0); + char **path = get_path_split(); + char *prog = path_lookup(cmd, path, 0); if (prog) { mingw_execve(prog, argv, environ); @@ -721,7 +712,7 @@ void mingw_execvp(const char *cmd, char *const *argv) } else errno = ENOENT; - mingw_free_path_split(path); + free_path_split(path); } char **copy_environ() @@ -882,7 +873,6 @@ struct passwd *getpwuid(int uid) return &p; } - static HANDLE timer_event; static HANDLE timer_thread; static int timer_interval; -- 2.11.4.GIT