lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* 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 | |
| 13 | int 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 | } |
| 24 | libc_hidden_def(fileno_unlocked) |
| 25 | |
| 26 | #ifndef __UCLIBC_HAS_THREADS__ |
| 27 | strong_alias(fileno_unlocked,fileno) |
| 28 | libc_hidden_def(fileno) |
| 29 | #endif |
| 30 | |
| 31 | #elif defined __UCLIBC_HAS_THREADS__ |
| 32 | |
| 33 | int 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 | } |
| 46 | libc_hidden_def(fileno) |
| 47 | |
| 48 | #endif |