From 6b17197be450fd67d3fde7208bbb1ea0160b73f9 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Tue, 19 Feb 2008 22:15:17 +0100 Subject: [PATCH] Windows: convert '\\' to '/' in sanitary_path_copy(). sanitary_path_copy() is only used by prefix_path(). A helper function is_dir_sep() is introduced that checks for both '/' and '\\' on Windows. Note that the remaining checks for '/' in prefix_path() don't need to to be converted to is_dir_sep() since they operate on the sanitized path. Signed-off-by: Johannes Sixt --- setup.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/setup.c b/setup.c index 18ddfae04f..b80653c32b 100644 --- a/setup.c +++ b/setup.c @@ -4,13 +4,26 @@ static int inside_git_dir = -1; static int inside_work_tree = -1; +#ifdef __MINGW32__ +static inline int is_dir_sep(char c) { return c == '/' || c == '\\'; } +#else +static inline int is_dir_sep(char c) { return c == '/'; } +#endif + static int sanitary_path_copy(char *dst, const char *src) { char *dst0 = dst; - if (*src == '/') { +#ifdef __MINGW32__ + if (isalpha(*src) && src[1] == ':') { + src += 2; + dst += 2; + dst0 += 2; + } +#endif + if (is_dir_sep(*src)) { *dst++ = '/'; - while (*src == '/') + while (is_dir_sep(*src)) src++; } @@ -32,9 +45,12 @@ static int sanitary_path_copy(char *dst, const char *src) src++; break; case '/': +#ifdef __MINGW32__ + case '\\': +#endif /* (2) */ src += 2; - while (*src == '/') + while (is_dir_sep(*src)) src++; continue; case '.': @@ -44,9 +60,12 @@ static int sanitary_path_copy(char *dst, const char *src) src += 2; goto up_one; case '/': +#ifdef __MINGW32__ + case '\\': +#endif /* (4) */ src += 3; - while (*src == '/') + while (is_dir_sep(*src)) src++; goto up_one; } @@ -54,11 +73,11 @@ static int sanitary_path_copy(char *dst, const char *src) } /* copy up to the next '/', and eat all '/' */ - while ((c = *src++) != '\0' && c != '/') + while ((c = *src++) != '\0' && !is_dir_sep(c)) *dst++ = c; - if (c == '/') { - *dst++ = c; - while (c == '/') + if (is_dir_sep(c)) { + *dst++ = '/'; + while (is_dir_sep(c)) c = *src++; src--; } else if (!c) @@ -77,7 +96,7 @@ static int sanitary_path_copy(char *dst, const char *src) if (dst <= dst0) break; c = *dst--; - if (c == '/') { + if (c == '/') { /* MinGW: cannot be '\\' anymore */ dst += 2; break; }