blob: 0bd0e9889eb02b013eb31feea112dd1031bdbc15 [file] [log] [blame]
Rich Felker0b44a032011-02-12 00:22:29 -05001#include "stdio_impl.h"
Rich Felkerb39b47b2018-08-28 18:40:15 -04002#include <errno.h>
Rich Felker0b44a032011-02-12 00:22:29 -05003
4int fileno(FILE *f)
5{
Rich Felkerc8cb6bc2012-10-24 23:16:41 -04006 FLOCK(f);
Rich Felkerb39b47b2018-08-28 18:40:15 -04007 int fd = f->fd;
Rich Felkerc8cb6bc2012-10-24 23:16:41 -04008 FUNLOCK(f);
Rich Felkerb39b47b2018-08-28 18:40:15 -04009 if (fd < 0) {
10 errno = EBADF;
11 return -1;
12 }
13 return fd;
Rich Felker0b44a032011-02-12 00:22:29 -050014}
15
16weak_alias(fileno, fileno_unlocked);