From 2c19171bc113241ee7c630c9ab46d2e95c18c942 Mon Sep 17 00:00:00 2001 From: "Tim J. Robbins" Date: Mon, 13 Jan 2003 02:58:18 +0000 Subject: [PATCH] Lock the stream before calling __sfileno() to retrieve the file descriptor. 1003.1-2001 requires that fileno() behave as if it locks the stream. --- lib/libc/stdio/fileno.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/libc/stdio/fileno.c b/lib/libc/stdio/fileno.c index 97f25e37a33..d7bf93deeaa 100644 --- a/lib/libc/stdio/fileno.c +++ b/lib/libc/stdio/fileno.c @@ -40,7 +40,10 @@ static char sccsid[] = "@(#)fileno.c 8.1 (Berkeley) 6/4/93"; #include __FBSDID("$FreeBSD$"); +#include "namespace.h" #include +#include "un-namespace.h" +#include "libc_private.h" /* * fileno has traditionally been a macro in . That is @@ -51,6 +54,11 @@ __FBSDID("$FreeBSD$"); int fileno(FILE *fp) { - /* ??? - Should probably use atomic_read. */ - return (__sfileno(fp)); + int fd; + + FLOCKFILE(fp); + fd = __sfileno(fp); + FUNLOCKFILE(fp); + + return (fd); }