fileno.c 985 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #include "_stdio.h"
  8. /* libc_hidden_proto(fileno_unlocked) */
  9. #ifdef __DO_UNLOCKED
  10. int fileno_unlocked(register FILE *stream)
  11. {
  12. __STDIO_STREAM_VALIDATE(stream);
  13. if ((!__STDIO_STREAM_IS_CUSTOM(stream)) && (stream->__filedes >= 0)) {
  14. return stream->__filedes;
  15. }
  16. __set_errno(EBADF);
  17. return -1;
  18. }
  19. libc_hidden_def(fileno_unlocked)
  20. #ifndef __UCLIBC_HAS_THREADS__
  21. /* libc_hidden_proto(fileno) */
  22. strong_alias(fileno_unlocked,fileno)
  23. libc_hidden_def(fileno)
  24. #endif
  25. #elif defined __UCLIBC_HAS_THREADS__
  26. /* libc_hidden_proto(fileno) */
  27. int fileno(register FILE *stream)
  28. {
  29. int retval;
  30. __STDIO_AUTO_THREADLOCK_VAR;
  31. __STDIO_AUTO_THREADLOCK(stream);
  32. retval = fileno_unlocked(stream);
  33. __STDIO_AUTO_THREADUNLOCK(stream);
  34. return retval;
  35. }
  36. libc_hidden_def(fileno)
  37. #endif