diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2012-07-09 12:13:16 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2012-07-09 12:13:16 +0000 |
commit | 821c8b9aacac0dde42d6d9a957ca7534ae3fedfc (patch) | |
tree | 357978db52869e776973dcddc63caedc9af7fbc5 | |
parent | c416f16d4483b6e2d4684fa3200b19619a5143b7 (diff) | |
download | newlib-821c8b9aacac0dde42d6d9a957ca7534ae3fedfc.zip newlib-821c8b9aacac0dde42d6d9a957ca7534ae3fedfc.tar.gz newlib-821c8b9aacac0dde42d6d9a957ca7534ae3fedfc.tar.bz2 |
* 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/ChangeLog | 8 | ||||
-rw-r--r-- | newlib/libc/stdio/fileno.c | 9 |
2 files changed, 16 insertions, 1 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 072c832..f8521f4 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 818f1a1..be8f3d6 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; } |