blob: 452572baee79f14ec4db6d0b052738b74cb6ba9f [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
2 *
3 * GNU Library General Public License (LGPL) version 2 or later.
4 *
5 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
6 */
7
8#include "_stdio.h"
9
10
11#ifdef __DO_UNLOCKED
12
13int fileno_unlocked(register FILE *stream)
14{
15 __STDIO_STREAM_VALIDATE(stream);
16
17 if ((!__STDIO_STREAM_IS_CUSTOM(stream)) && (stream->__filedes >= 0)) {
18 return stream->__filedes;
19 }
20
21 __set_errno(EBADF);
22 return -1;
23}
24libc_hidden_def(fileno_unlocked)
25
26#ifndef __UCLIBC_HAS_THREADS__
27strong_alias(fileno_unlocked,fileno)
28libc_hidden_def(fileno)
29#endif
30
31#elif defined __UCLIBC_HAS_THREADS__
32
33int fileno(register FILE *stream)
34{
35 int retval;
36 __STDIO_AUTO_THREADLOCK_VAR;
37
38 __STDIO_AUTO_THREADLOCK(stream);
39
40 retval = fileno_unlocked(stream);
41
42 __STDIO_AUTO_THREADUNLOCK(stream);
43
44 return retval;
45}
46libc_hidden_def(fileno)
47
48#endif