fileno.c 850 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. weak_alias(__fileno_unlocked,fileno_unlocked);
  19. #ifndef __UCLIBC_HAS_THREADS__
  20. weak_alias(__fileno_unlocked,fileno);
  21. #endif
  22. #elif defined __UCLIBC_HAS_THREADS__
  23. int fileno(register FILE *stream)
  24. {
  25. int retval;
  26. __STDIO_AUTO_THREADLOCK_VAR;
  27. __STDIO_AUTO_THREADLOCK(stream);
  28. retval = __fileno_unlocked(stream);
  29. __STDIO_AUTO_THREADUNLOCK(stream);
  30. return retval;
  31. }
  32. #endif