From 25fe217b86ca40c53e710d776e120dfa0d81f60b Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Wed, 5 Mar 2008 21:51:27 +0100 Subject: Windows: Treat Windows style path names. GIT's guts work with a forward slash as a path separators. We do not change that. Rather we make sure that only "normalized" paths enter the depths of the machinery. We have to translate backslashes to forward slashes in the prefix and in command line arguments. Fortunately, all of them are passed through functions in setup.c. A macro has_dos_drive_path() is defined that checks whether a path begins with a drive letter+colon combination. This predicate is always false on Unix. Another macro is_dir_sep() abstracts that a backslash is also a directory separator on Windows. Signed-off-by: Johannes Sixt --- compat/mingw.c | 13 +++++++++++++ compat/mingw.h | 9 +++++++++ 2 files changed, 22 insertions(+) (limited to 'compat') diff --git a/compat/mingw.c b/compat/mingw.c index 075448d24..4e559bdc9 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -40,6 +40,19 @@ struct tm *localtime_r(const time_t *timep, struct tm *result) return result; } +#undef getcwd +char *mingw_getcwd(char *pointer, int len) +{ + int i; + char *ret = getcwd(pointer, len); + if (!ret) + return ret; + for (i = 0; pointer[i]; i++) + if (pointer[i] == '\\') + pointer[i] = '/'; + return ret; +} + struct passwd *getpwuid(int uid) { static struct passwd p; diff --git a/compat/mingw.h b/compat/mingw.h index 22aae0077..a954014ff 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -133,8 +133,17 @@ struct passwd *getpwuid(int uid); int setitimer(int type, struct itimerval *in, struct itimerval *out); int sigaction(int sig, struct sigaction *in, struct sigaction *out); +/* + * replacements of existing functions + */ + +char *mingw_getcwd(char *pointer, int len); +#define getcwd mingw_getcwd + /* * git specific compatibility */ +#define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':') +#define is_dir_sep(c) ((c) == '/' || (c) == '\\') #define PATH_SEP ';' -- cgit v1.2.1