* libc/stdio/fileno.c (fileno): Check if f is a valid stream. If not,

return -1 and set errno to EBADF per POSIX.
This commit is contained in:
Corinna Vinschen 2012-07-09 12:13:16 +00:00
parent c416f16d44
commit 821c8b9aac
2 changed files with 16 additions and 1 deletions

View File

@ -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:

View File

@ -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;
}