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 <dotzenlabs@gmail.com>
This commit is contained in:
Mike Pape
2007-08-06 16:11:19 -04:00
committed by Johannes Schindelin
parent 60096146d6
commit 3d9012418c
3 changed files with 18 additions and 5 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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)