fileno.c 880 B

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