From c9158195f6bf0a73bdd5d057d8db7f182397f17c Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Fri, 10 Sep 2010 18:00:36 +1000 Subject: win32: add next_path_sep() --- include/mingw.h | 4 ++++ win32/process.c | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/mingw.h b/include/mingw.h index f9773a9a2..57fa6177d 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -309,6 +309,10 @@ pid_t mingw_spawn_1(int mode, const char *cmd, const char *const *argv, const ch #define execve mingw_execve #define execv mingw_execv +const char * next_path_sep(const char *path); +#define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':') +#define is_absolute_path(path) ((path)[0] == '/' || has_dos_drive_prefix(path)) + /* * helpers */ diff --git a/win32/process.c b/win32/process.c index 55f5fef14..0936e1c42 100644 --- a/win32/process.c +++ b/win32/process.c @@ -9,6 +9,26 @@ int waitpid(pid_t pid, int *status, unsigned options) return -1; } +const char * +next_path_sep(const char *path) +{ + static const char *from = NULL, *to; + static int has_semicolon; + int len = strlen(path); + + if (!from || !(path >= from && path+len <= to)) { + from = path; + to = from+len; + has_semicolon = strchr(path, ';') != NULL; + } + + /* Semicolons take precedence, it's Windows PATH */ + if (has_semicolon) + return strchr(path, ';'); + /* PATH=C:, not really a separator */ + return strchr(has_dos_drive_prefix(path) ? path+2 : path, ':'); +} + static const char * parse_interpreter(const char *cmd) { -- cgit v1.2.3-55-g6feb