X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Ffileno.c;h=0bd0e9889eb02b013eb31feea112dd1031bdbc15;hb=9b132e556774c744f9052581d2d8d0fab417e97c;hp=ba7f9391b1ec9baa6023f9a66f569b46a1f85ba2;hpb=c8cb6bcdf009e94c12c6e256b8e24a9bc5fdaf05;p=musl diff --git a/src/stdio/fileno.c b/src/stdio/fileno.c index ba7f9391..0bd0e988 100644 --- a/src/stdio/fileno.c +++ b/src/stdio/fileno.c @@ -1,13 +1,16 @@ #include "stdio_impl.h" +#include int fileno(FILE *f) { - /* f->fd never changes, but the lock must be obtained and released - * anyway since this function cannot return while another thread - * holds the lock. */ FLOCK(f); + int fd = f->fd; FUNLOCK(f); - return f->fd; + if (fd < 0) { + errno = EBADF; + return -1; + } + return fd; } weak_alias(fileno, fileno_unlocked);