From 821c8b9aacac0dde42d6d9a957ca7534ae3fedfc Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 9 Jul 2012 12:13:16 +0000 Subject: * libc/stdio/fileno.c (fileno): Check if f is a valid stream. If not, return -1 and set errno to EBADF per POSIX. --- newlib/libc/stdio/fileno.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'newlib/libc') 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 +#include #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; } -- cgit v1.2.3