summaryrefslogtreecommitdiff
path: root/libc/stdio/stdio_ext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libc/stdio/stdio_ext.cpp')
-rw-r--r--libc/stdio/stdio_ext.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/libc/stdio/stdio_ext.cpp b/libc/stdio/stdio_ext.cpp
index fea44f68b..88e59510d 100644
--- a/libc/stdio/stdio_ext.cpp
+++ b/libc/stdio/stdio_ext.cpp
@@ -27,6 +27,8 @@
*/
#include <stdio_ext.h>
+
+#include <errno.h>
#include <stdlib.h>
#include "local.h"
@@ -74,7 +76,7 @@ void _flushlbf() {
}
int __fsetlocking(FILE* fp, int type) {
- int old_state = _EXT(fp)->_stdio_handles_locking ? FSETLOCKING_INTERNAL : FSETLOCKING_BYCALLER;
+ int old_state = _EXT(fp)->_caller_handles_locking ? FSETLOCKING_BYCALLER : FSETLOCKING_INTERNAL;
if (type == FSETLOCKING_QUERY) {
return old_state;
}
@@ -84,7 +86,7 @@ int __fsetlocking(FILE* fp, int type) {
__libc_fatal("Bad type (%d) passed to __fsetlocking", type);
}
- _EXT(fp)->_stdio_handles_locking = (type == FSETLOCKING_INTERNAL);
+ _EXT(fp)->_caller_handles_locking = (type == FSETLOCKING_BYCALLER);
return old_state;
}
@@ -99,3 +101,12 @@ int feof_unlocked(FILE* fp) {
int ferror_unlocked(FILE* fp) {
return __sferror(fp);
}
+
+int fileno_unlocked(FILE* fp) {
+ int fd = fp->_file;
+ if (fd == -1) {
+ errno = EBADF;
+ return -1;
+ }
+ return fd;
+}