Windows: redirect fopen("/dev/null") to fopen("nul")
PATCH 1/1 Windows: redirect fopen("/dev/null") to fopen("nul")
From: Johannes Sixt <[email protected]>
An instance of fopen("/dev/null",...) was added to the code base. On Windows, we have to use "nul" instead. This implements a compatibility wrapper of fopen() that checks for this particular condition.
--- compat/mingw.c | 8 ++++++++ compat/mingw.h | 3 +++ 2 files changed, 11 insertions(+), 0 deletions(-)
compat/mingw.c +8 -0
@@ -140,6 +140,14 @@ 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); +} +/* * The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC. * Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
compat/mingw.h +3 -0
@@ -170,6 +170,9 @@ 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 +char *mingw_getcwd (char *pointer,int len);#define getcwd mingw_getcwd
Signature · 1 line
1.7.0.1285.g1a907.dirty
Quoted 5 lines · * Johannes Sixt ([email protected]) [100225 03:49]:
From: Johannes Sixt <[email protected]>
An instance of
fopen("/dev/null",...)was added to the code base. On Windows, we have to use "nul" instead. This implements a compatibility wrapper offopen()that checks for this particular condition.
Doesn't store_updated_refs do this too?
--larry
Quoted 8 lines · Larry D'Anna
Quoted 5 lines · * Johannes Sixt ([email protected]) [100225 03:49]:
From: Johannes Sixt <[email protected]>
An instance of
fopen("/dev/null",...)was added to the code base. On Windows, we have to use "nul" instead. This implements a compatibility wrapper offopen()that checks for this particular condition.Doesn't
store_updated_refsdo this too?
I think there is no problem, as the patch covers that case, too.
PATCH 1/1 Windows: redirect f[re]open("/dev/null") to f[re]open("nul")
From: Johannes Sixt <[email protected]>
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.
---
Quoted 4 lines · Junio C Hamano
Quoted 1 line · Larry D'Anna
Doesn't
store_updated_refsdo this too?I think there is no problem, as the patch covers that case, too.
Nevertheless, we should do this, but this is now not specific to ld/maint-diff-quiet-w anymore.
-- Hannes
compat/mingw.c | 16 ++++++++++++++++ compat/mingw.h | 6 ++++++ t/t5510-fetch.sh | 7 +++++++ t/t6023-merge-file.sh | 4 ++++ 4 files changed, 33 insertions(+), 0 deletions(-)
compat/mingw.c +16 -0
@@ -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.
compat/mingw.h +6 -0
@@ -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
t/t5510-fetch.sh +7 -0
@@ -342,6 +342,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 &&
t/t6023-merge-file.sh +4 -0
@@ -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"
Signature · 1 line
1.7.0.1287.g50986
builtin-merge-file.c and daemon.c use freopen() on /dev/null; would it also need to be wrapped?