diff options
Diffstat (limited to 'newlib/libc')
-rw-r--r-- | newlib/libc/stdio/fileno.c | 9 |
1 files changed, 8 insertions, 1 deletions
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; } |