From 3d9012418c93b5e5f0ada041e1fc071cac48cbfa Mon Sep 17 00:00:00 2001 From: Mike Pape Date: Mon, 6 Aug 2007 16:11:19 -0400 Subject: [PATCH] Added is_dev_null check because Windows /dev/null is nul. This function should be called to test for /dev/null when nul on Windows can also be accepted. The is_dev_null function in builtin-apply.c was renamed. Signed-off-by: Mike Pape --- builtin-apply.c | 8 ++++---- cache.h | 9 +++++++++ diff-lib.c | 6 +++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/builtin-apply.c b/builtin-apply.c index 0a0b4a9e3f..f8cde7f3f5 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -222,7 +222,7 @@ static unsigned long linelen(const char *buffer, unsigned long size) return len; } -static int is_dev_null(const char *str) +static int is_dev_null_line(const char *str) { return !memcmp("/dev/null", str, 9) && isspace(str[9]); } @@ -333,7 +333,7 @@ static int guess_p_value(const char *nameline) char *name, *cp; int val = -1; - if (is_dev_null(nameline)) + if (is_dev_null_line(nameline)) return -1; name = find_name(nameline, NULL, 0, TERM_SPACE | TERM_TAB); if (!name) @@ -381,12 +381,12 @@ static void parse_traditional_patch(const char *first, const char *second, struc p_value_known = 1; } } - if (is_dev_null(first)) { + if (is_dev_null_line(first)) { patch->is_new = 1; patch->is_delete = 0; name = find_name(second, NULL, p_value, TERM_SPACE | TERM_TAB); patch->new_name = name; - } else if (is_dev_null(second)) { + } else if (is_dev_null_line(second)) { patch->is_new = 0; patch->is_delete = 1; name = find_name(first, NULL, p_value, TERM_SPACE | TERM_TAB); diff --git a/cache.h b/cache.h index 91e9f7109f..f13e1b74a1 100644 --- a/cache.h +++ b/cache.h @@ -364,6 +364,15 @@ static inline int is_absolute_path(const char *path) return path[0] == '/' || (isalpha(path[0]) && path[1] == ':'); } +static inline int is_dev_null(const char *str) +{ +#ifdef __MINGW32__ + if (!strcmp(str, "nul")) + return 1; +#endif + return !strcmp(str, "/dev/null"); +} + /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ extern int sha1_object_info(const unsigned char *, unsigned long *); extern void * read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size); diff --git a/diff-lib.c b/diff-lib.c index 92c0e39ad6..9a424621ed 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -34,7 +34,7 @@ static int get_mode(const char *path, int *mode) { struct stat st; - if (!path || !strcmp(path, "/dev/null")) + if (!path || is_dev_null(path)) *mode = 0; else if (!strcmp(path, "-")) *mode = ntohl(create_ce_mode(0666)); @@ -229,6 +229,10 @@ static int is_outside_repo(const char *path, int nongit, const char *prefix) int i; if (nongit || !strcmp(path, "-") || path[0] == '/') return 1; +#ifdef __MINGW32__ + if (!strcmp(path, "nul")) + return 1; +#endif if (prefixcmp(path, "../")) return 0; if (!prefix) -- 2.11.4.GIT