musl - musl - an implementation of the standard library for Linux-based systems

index : musl
musl - an implementation of the standard library for Linux-based systems
summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/stdio/fileno.c 11
1 files changed, 7 insertions, 4 deletions
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);
generated by cgit v1.2.1 (git 2.18.0) at 2025年09月28日 17:58:35 +0000

AltStyle によって変換されたページ (->オリジナル) /