index 3b111ea7cf5f68ecca085f5a56421ea190e1771a..cc3fb380c1f3471f0371ba54ca2f338f90a8d4fc 100644 (file)
--- a/setup.c
+++ b/setup.c
static int sanitary_path_copy(char *dst, const char *src)
{
static int sanitary_path_copy(char *dst, const char *src)
{
- char *dst0 = dst;
+ char *dst0;
- if (*src == '/') {
+ if (has_dos_drive_prefix(src)) {
+ *dst++ = *src++;
+ *dst++ = *src++;
+ }
+ dst0 = dst;
+
+ if (is_dir_sep(*src)) {
*dst++ = '/';
*dst++ = '/';
- while (*src == '/')
+ while (is_dir_sep(*src))
src++;
}
src++;
}
* (4) "../" -- strip one, eat slash and continue.
*/
if (c == '.') {
* (4) "../" -- strip one, eat slash and continue.
*/
if (c == '.') {
- switch (src[1]) {
- case '\0':
+ if (!src[1]) {
/* (1) */
src++;
/* (1) */
src++;
- break;
- case '/':
+ } else if (is_dir_sep(src[1])) {
/* (2) */
src += 2;
/* (2) */
src += 2;
- while (*src == '/')
+ while (is_dir_sep(*src))
src++;
continue;
src++;
continue;
- case '.':
- switch (src[2]) {
- case '\0':
+ } else if (src[1] == '.') {
+ if (!src[2]) {
/* (3) */
src += 2;
goto up_one;
/* (3) */
src += 2;
goto up_one;
- case '/':
+ } else if (is_dir_sep(src[2])) {
/* (4) */
src += 3;
/* (4) */
src += 3;
- while (*src == '/')
+ while (is_dir_sep(*src))
src++;
goto up_one;
}
src++;
goto up_one;
}
}
/* copy up to the next '/', and eat all '/' */
}
/* copy up to the next '/', and eat all '/' */
- while ((c = *src++) != '\0' && c != '/')
+ while ((c = *src++) != '\0' && !is_dir_sep(c))
*dst++ = 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)
c = *src++;
src--;
} else if (!c)
if (dst <= dst0)
break;
c = *dst--;
if (dst <= dst0)
break;
c = *dst--;
- if (c == '/') {
+ if (c == '/') { /* MinGW: cannot be '\\' anymore */
dst += 2;
break;
}
dst += 2;
break;
}
const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
{
static char path[PATH_MAX];
const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
{
static char path[PATH_MAX];
+#ifndef __MINGW32__
if (!pfx || !*pfx || is_absolute_path(arg))
return arg;
memcpy(path, pfx, pfx_len);
strcpy(path + pfx_len, arg);
if (!pfx || !*pfx || is_absolute_path(arg))
return arg;
memcpy(path, pfx, pfx_len);
strcpy(path + pfx_len, arg);
+#else
+ char *p;
+ /* don't add prefix to absolute paths, but still replace '\' by '/' */
+ if (is_absolute_path(arg))
+ pfx_len = 0;
+ else
+ memcpy(path, pfx, pfx_len);
+ strcpy(path + pfx_len, arg);
+ for (p = path + pfx_len; *p; p++)
+ if (*p == '\\')
+ *p = '/';
+#endif
return path;
}
return path;
}
const char *gitdirenv;
const char *gitfile_dir;
int len, offset;
const char *gitdirenv;
const char *gitfile_dir;
int len, offset;
+ int minoffset = 0;
/*
* Let's assume that we are in a git repository.
/*
* Let's assume that we are in a git repository.
if (!getcwd(cwd, sizeof(cwd)-1))
die("Unable to read current working directory");
if (!getcwd(cwd, sizeof(cwd)-1))
die("Unable to read current working directory");
+ if (has_dos_drive_prefix(cwd))
+ minoffset = 2;
/*
* Test in the following order (relative to the cwd):
/*
* Test in the following order (relative to the cwd):
}
chdir("..");
do {
}
chdir("..");
do {
- if (!offset) {
+ if (offset <= minoffset) {
if (nongit_ok) {
if (chdir(cwd))
die("Cannot come back to cwd");
if (nongit_ok) {
if (chdir(cwd))
die("Cannot come back to cwd");
}
die("Not a git repository");
}
}
die("Not a git repository");
}
- } while (cwd[--offset] != '/');
+ } while (offset > minoffset && cwd[--offset] != '/');
}
inside_git_dir = 0;
}
inside_git_dir = 0;