Lock the stream before calling __sfileno() to retrieve the file descriptor.

1003.1-2001 requires that fileno() behave as if it locks the stream.
This commit is contained in:
Tim J. Robbins 2003-01-13 02:58:18 +00:00
parent 83bb3b4979
commit 2c19171bc1
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=109155

View File

@ -40,7 +40,10 @@ static char sccsid[] = "@(#)fileno.c 8.1 (Berkeley) 6/4/93";
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "namespace.h"
#include <stdio.h>
#include "un-namespace.h"
#include "libc_private.h"
/*
* fileno has traditionally been a macro in <stdio.h>. 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);
}