mirror of https://git.musl-libc.org/git/musl
Browse Source
this is a POSIX requirement. also remove the gratuitous locking shenanigans and simply access f->fd under control of the lock. there is no advantage to not doing so, and it made the correctness non-obvious at best.master
1 changed files with 7 additions and 4 deletions
@ -1,13 +1,16 @@ |
|||||
#include "stdio_impl.h" |
#include "stdio_impl.h" |
||||
|
#include <errno.h> |
||||
|
|
||||
int fileno(FILE *f) |
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); |
FLOCK(f); |
||||
|
int fd = f->fd; |
||||
FUNLOCK(f); |
FUNLOCK(f); |
||||
return f->fd; |
if (fd < 0) { |
||||
|
errno = EBADF; |
||||
|
return -1; |
||||
|
} |
||||
|
return fd; |
||||
} |
} |
||||
|
|
||||
weak_alias(fileno, fileno_unlocked); |
weak_alias(fileno, fileno_unlocked); |
||||
|
|||||
Loading…
Reference in new issue