author | Rich Felker <dalias@aerifal.cx> | 2018年08月28日 18:40:15 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2018年08月28日 18:41:12 -0400 |
commit | b39b47bac8ee5505cfc595000a140c35460e1cac (patch) | |
tree | 4541df8890654a784bdb40b9f5fe94dc028ea2e8 /src | |
parent | baf95a5aefe885ef8a675759c63d43649d312ec6 (diff) | |
download | musl-b39b47bac8ee5505cfc595000a140c35460e1cac.tar.gz |
-rw-r--r-- | src/stdio/fileno.c | 11 |
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 <errno.h> 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); |