diff options
author | KO Myung-Hun <komh78@gmail.com> | 2014-12-05 15:01:36 +0900 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2014-12-08 13:56:55 -0700 |
commit | 3c4e08331004fb2c43d42f521e1b546222ef8d6e (patch) | |
tree | 77dc6ab846af907ceae71c3e55b3214972d9ba04 /lib | |
parent | 023ca2dd07d0f300fea99a04a8e289ad98545034 (diff) | |
download | gnulib-3c4e08331004fb2c43d42f521e1b546222ef8d6e.tar.gz |
freopen: workaround freopen() on OS/2 kLIBC
On OS/2 kLIBC, freopen() returns NULL even if it is successful if
filename is NULL.
* lib/freopen.c (rpl_freopen): Workaround.
* m4/freopen.m4: Add os2* case.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/freopen.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/freopen.c b/lib/freopen.c index 384eba64dd..0d582bf833 100644 --- a/lib/freopen.c +++ b/lib/freopen.c @@ -26,6 +26,8 @@ #include <stdio.h> #undef __need_FILE +#include <errno.h> + static FILE * orig_freopen (const char *filename, const char *mode, FILE *stream) { @@ -42,10 +44,24 @@ orig_freopen (const char *filename, const char *mode, FILE *stream) FILE * rpl_freopen (const char *filename, const char *mode, FILE *stream) { + FILE *result; + #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ if (filename != NULL && strcmp (filename, "/dev/null") == 0) filename = "NUL"; #endif - return orig_freopen (filename, mode, stream); + /* Clear errno to check the success of freopen() with it */ + errno = 0; + + result = orig_freopen (filename, mode, stream); + +#ifdef __KLIBC__ + /* On OS/2 kLIBC, freopen() returns NULL even if it is successful + if filename is NULL. */ + if (!filename && !result && !errno) + result = stream; +#endif + + return result; } |