[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 15/21] freopen: workaround freopen() on OS/2 kLIBC
From: |
KO Myung-Hun |
Subject: |
[PATCH 15/21] freopen: workaround freopen() on OS/2 kLIBC |
Date: |
Sun, 30 Nov 2014 13:20:17 +0900 |
On OS/2 kLIBC, freopen() returns NULL even if it is successful if
filename is NULL.
* lib/freopen-safer.c (klibc_freopen): New.
* lib/freopen.c (orig_freopen): Workaround.
---
lib/freopen-safer.c | 19 +++++++++++++++++++
lib/freopen.c | 11 +++++++++++
2 files changed, 30 insertions(+)
diff --git a/lib/freopen-safer.c b/lib/freopen-safer.c
index 714dc1d..1cb7052 100644
--- a/lib/freopen-safer.c
+++ b/lib/freopen-safer.c
@@ -44,6 +44,25 @@ protect_fd (int fd)
return true;
}
+#ifdef __KLIBC__
+/* Workaround for freopen() on OS/2 kLIBC */
+static FILE *
+klibc_freopen (const char *filename, const char *mode, FILE *stream)
+{
+ FILE *result = freopen (filename, mode, stream);
+
+ /* On OS/2 kLIBC, freopen() returns NULL even if it is successful
+ if filename is NULL. */
+ if (!result && !errno)
+ result = stream;
+
+ return result;
+}
+
+# undef freopen
+# define freopen klibc_freopen
+#endif
+
/* Like freopen, but guarantee that reopening stdin, stdout, or stderr
preserves the invariant that STDxxx_FILENO==fileno(stdxxx), and
that no other stream will interfere with the standard streams.
diff --git a/lib/freopen.c b/lib/freopen.c
index 384eba6..8b3ad1e 100644
--- a/lib/freopen.c
+++ b/lib/freopen.c
@@ -29,7 +29,18 @@
static FILE *
orig_freopen (const char *filename, const char *mode, FILE *stream)
{
+#ifdef __KLIBC__
+ FILE *result = freopen (filename, mode, stream);
+
+ /* On OS/2 kLIBC, freopen() returns NULL even if it is successful
+ if filename is NULL. */
+ if (!result && !errno)
+ result = stream;
+
+ return result;
+#else
return freopen (filename, mode, stream);
+#endif
}
/* Specification. */
--
1.8.5.2
- [PATCH 11/21] pipe-filter-aux: undefine HAVE_SELECT on KLIBC, (continued)
- [PATCH 11/21] pipe-filter-aux: undefine HAVE_SELECT on KLIBC, KO Myung-Hun, 2014/11/30
- [PATCH 14/21] getdtablesize: do not use getrlimit() on OS/2 kLIBC, KO Myung-Hun, 2014/11/30
- [PATCH 13/21] w32spawn: clear SHELL_SPECIAL_CHARS and SHELL_SPACE_CHAR on OS/2 kLIBC, KO Myung-Hun, 2014/11/30
- [PATCH 16/21] wcwidth: fix 'conflicting types' error for `__wcwidth' on OS/2 kLIBC, KO Myung-Hun, 2014/11/30
- [PATCH 18/21] Workaround for dirfd() on OS/2 kLIBC, KO Myung-Hun, 2014/11/30
- [PATCH 15/21] freopen: workaround freopen() on OS/2 kLIBC,
KO Myung-Hun <=
- [PATCH 17/21] Workaround for D_INO_IN_DIRENT on OS/2 kLIBC, KO Myung-Hun, 2014/11/30
- [PATCH 20/21] fdopendir: port to OS/2 kLIBC, KO Myung-Hun, 2014/11/30
- [PATCH 21/21] bootstrap: fix 'find: missing argument to `-exec'', KO Myung-Hun, 2014/11/30
- [PATCH 19/21] utimens: define HAVE_WORKING_UTIMES to 1 on OS/2 kLIBC, KO Myung-Hun, 2014/11/30