Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2012-07-09 16:13:16 +0400
committerCorinna Vinschen <corinna@vinschen.de>2012-07-09 16:13:16 +0400
commit821c8b9aacac0dde42d6d9a957ca7534ae3fedfc (patch)
tree357978db52869e776973dcddc63caedc9af7fbc5
parentc416f16d4483b6e2d4684fa3200b19619a5143b7 (diff)
* libc/stdio/fileno.c (fileno): Check if f is a valid stream. If not,
return -1 and set errno to EBADF per POSIX.
-rw-r--r--newlib/ChangeLog8
-rw-r--r--newlib/libc/stdio/fileno.c9
2 files changed, 16 insertions, 1 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index 072c832fe..f8521f47b 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,3 +1,11 @@
+2012-07-09 Corinna Vinschen <vinschen@redhat.com>
+
+ * libc/stdio/fileno.c (fileno): Check if f is a valid stream. If not,
+ return -1 and set errno to EBADF per POSIX.
+
+2012-07-06 Corinna Vinschen <vinschen@redhat.com>
+
+
2012-07-06 Corinna Vinschen <vinschen@redhat.com>
Allow building of Cygwin using Mingw64 SDK headers:
diff --git a/newlib/libc/stdio/fileno.c b/newlib/libc/stdio/fileno.c
index 818f1a1ca..be8f3d66a 100644
--- a/newlib/libc/stdio/fileno.c
+++ b/newlib/libc/stdio/fileno.c
@@ -47,6 +47,7 @@ Supporting OS subroutines required: none.
#include <_ansi.h>
#include <stdio.h>
+#include <errno.h>
#include "local.h"
int
@@ -56,7 +57,13 @@ _DEFUN(fileno, (f),
int result;
CHECK_INIT (_REENT, f);
_newlib_flockfile_start (f);
- result = __sfileno (f);
+ if (f->_flags)
+ result = __sfileno (f);
+ else
+ {
+ result = -1;
+ _REENT->_errno = EBADF;
+ }
_newlib_flockfile_end (f);
return result;
}