git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH ld/maint-diff-quiet-w] Windows: redirect fopen("/dev/null") to fopen("nul")

From
Johannes Sixt <j.sixt@viscovery.net>
Date
Feb 25, 2010, 08:49 UTC
Message-ID
<4B86399E.3090508@viscovery.net>
From: Johannes Sixt <j6t@kdbg.org>

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.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 compat/mingw.c |    8 ++++++++
 compat/mingw.h |    3 +++
 2 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/compat/mingw.c b/compat/mingw.c
index 5edf152..57aec93 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -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.
diff --git a/compat/mingw.h b/compat/mingw.h
index f53bcca..e187b04 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -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
-- 
1.7.0.1285.g1a907.dirty
Next: Larry D'Anna
Message 1 of 5 in “Windows: redirect fopen("/dev/null") to fopen("nul")”
  1. Windows: redirect fopen("/dev/null") to fopen("nul")Johannes Sixt, Feb 25, 2010
  2. Larry D'AnnaFeb 25, 2010
  3. Junio C HamanoFeb 25, 2010
  4. Windows: redirect f[re]open("/dev/null") to f[re]open("nul")Johannes Sixt, Feb 25, 2010
  5. Junio C HamanoFeb 25, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.