Index: include/stdio.h =================================================================== --- include/stdio.h +++ include/stdio.h @@ -302,7 +302,9 @@ char *ctermid(char *); FILE *fdopen(int, const char *); -int fileno(FILE *); +#ifndef __FILENO_C +static __inline int fileno(FILE *); +#endif #endif /* __POSIX_VISIBLE */ #if __POSIX_VISIBLE >= 199209 @@ -328,7 +330,9 @@ void clearerr_unlocked(FILE *); int feof_unlocked(FILE *); int ferror_unlocked(FILE *); -int fileno_unlocked(FILE *); +#ifndef __FILENO_C +static __inline int fileno_unlocked(FILE *); +#endif #endif #if __POSIX_VISIBLE >= 200112 @@ -482,6 +486,30 @@ extern int __isthreaded; +#if __POSIX_VISIBLE +#ifndef __FILENO_C +static __inline int +fileno(FILE *p) +{ + return (!__isthreaded ? __sfileno(p) : (__fileno_mt)(p)); +} +#endif +#endif + +#if __BSD_VISIBLE +/* + * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12 + * B.8.2.7 for the rationale behind the *_unlocked() macros. + */ +#ifndef __FILENO_C +static __inline int +fileno_unlocked(FILE *p) +{ + return __sfileno(p); +} +#endif +#endif + #ifndef __cplusplus #define __sfeof(p) (((p)->_flags & __SEOF) != 0) @@ -494,10 +522,6 @@ #define ferror(p) (!__isthreaded ? __sferror(p) : (ferror)(p)) #define clearerr(p) (!__isthreaded ? __sclearerr(p) : (clearerr)(p)) -#if __POSIX_VISIBLE -#define fileno(p) (!__isthreaded ? __sfileno(p) : (fileno)(p)) -#endif - #define getc(fp) (!__isthreaded ? __sgetc(fp) : (getc)(fp)) #define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : (putc)(x, fp)) @@ -512,7 +536,6 @@ #define feof_unlocked(p) __sfeof(p) #define ferror_unlocked(p) __sferror(p) #define clearerr_unlocked(p) __sclearerr(p) -#define fileno_unlocked(p) __sfileno(p) #endif #if __POSIX_VISIBLE >= 199506 #define getc_unlocked(fp) __sgetc(fp) Index: lib/libc/stdio/fileno.c =================================================================== --- lib/libc/stdio/fileno.c +++ lib/libc/stdio/fileno.c @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" +#define __FILENO_C #include #include "un-namespace.h" #include "libc_private.h" @@ -57,6 +58,12 @@ } int +__fileno_mt(FILE *fp) +{ + return fileno(fp); +} + +int fileno_unlocked(FILE *fp) {