summaryrefslogtreecommitdiff
path: root/lib/freopen.c
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2015-07-04 17:17:09 +0300
committerIgor Pashev <pashev.igor@gmail.com>2015-07-04 17:17:09 +0300
commitcc78bdc31749e9754120ae5a9d4849f4832b40a4 (patch)
tree4f9e3f2064e56651ed8d41ae9d8ce8b08fc5241b /lib/freopen.c
parent8425beb209e6fedf50bcdd934ced14dfa0d7b596 (diff)
parent71cd8e3a743046573744123777061b64881bf372 (diff)
downloadcoreutils-cc78bdc31749e9754120ae5a9d4849f4832b40a4.tar.gz
Merge tag 'upstream/8.24'
Upstream version 8.24 Conflicts: INSTALL Makefile.in aclocal.m4 build-aux/config.guess build-aux/config.rpath build-aux/config.sub build-aux/depcomp build-aux/missing build-aux/test-driver build-aux/texinfo.tex doc/coreutils.info doc/stamp-vti doc/version.texi gnulib-tests/Makefile.in po/Makefile.in.in
Diffstat (limited to 'lib/freopen.c')
-rw-r--r--lib/freopen.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/freopen.c b/lib/freopen.c
index 384eba64..7ceef765 100644
--- a/lib/freopen.c
+++ b/lib/freopen.c
@@ -1,5 +1,5 @@
/* Open a stream to a file.
- Copyright (C) 2007-2014 Free Software Foundation, Inc.
+ Copyright (C) 2007-2015 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -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;
}