Skip to content

Commit

Permalink
Windows: redirect f[re]open("/dev/null") to f[re]open("nul")
Browse files Browse the repository at this point in the history
On Windows, the equivalent of "/dev/null" is "nul". This implements
compatibility wrappers around fopen() and freopen() that check for this
particular file name.

The new tests exercise code paths where this is relevant.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Johannes Sixt authored and Junio C Hamano committed Feb 25, 2010
1 parent 251a495 commit 3fdcdbd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ int mingw_open (const char *filename, int oflags, ...)
return fd;
}

#undef fopen
FILE *mingw_fopen (const char *filename, const char *otype)
{
if (!strcmp(filename, "/dev/null"))
filename = "nul";
return fopen(filename, otype);
}

#undef freopen
FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream)
{
if (filename && !strcmp(filename, "/dev/null"))
filename = "nul";
return freopen(filename, otype, stream);
}

/*
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
Expand Down
6 changes: 6 additions & 0 deletions compat/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ int link(const char *oldpath, const char *newpath);
int mingw_open (const char *filename, int oflags, ...);
#define open mingw_open

FILE *mingw_fopen (const char *filename, const char *otype);
#define fopen mingw_fopen

FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream);
#define freopen mingw_freopen

char *mingw_getcwd(char *pointer, int len);
#define getcwd mingw_getcwd

Expand Down
7 changes: 7 additions & 0 deletions t/t5510-fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,13 @@ test_expect_success 'fetch into the current branch with --update-head-ok' '
'

test_expect_success 'fetch --dry-run' '
rm -f .git/FETCH_HEAD &&
git fetch --dry-run . &&
! test -f .git/FETCH_HEAD
'

test_expect_success "should be able to fetch with duplicate refspecs" '
mkdir dups &&
cd dups &&
Expand Down
4 changes: 4 additions & 0 deletions t/t6023-merge-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ cp new1.txt test.txt
test_expect_success "merge without conflict" \
"git merge-file test.txt orig.txt new2.txt"

cp new1.txt test.txt
test_expect_success "merge without conflict (--quiet)" \
"git merge-file --quiet test.txt orig.txt new2.txt"

cp new1.txt test2.txt
test_expect_success "merge without conflict (missing LF at EOF)" \
"git merge-file test2.txt orig.txt new2.txt"
Expand Down

0 comments on commit 3fdcdbd

Please sign in to comment.