fix integer overflow in WIFSTOPPED macro
[musl] / src / stdio / fileno.c
index 9ffb26d..0bd0e98 100644 (file)
@@ -1,8 +1,16 @@
 #include "stdio_impl.h"
+#include <errno.h>
 
 int fileno(FILE *f)
 {
-       return f->fd;
+       FLOCK(f);
+       int fd = f->fd;
+       FUNLOCK(f);
+       if (fd < 0) {
+               errno = EBADF;
+               return -1;
+       }
+       return fd;
 }
 
 weak_alias(fileno, fileno_unlocked);