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. weak_alias(__fileno_unlocked,fileno_unlocked);
  10. #ifndef __UCLIBC_HAS_THREADS__
  11. weak_alias(__fileno_unlocked,fileno);
  12. #endif
  13. int __fileno_unlocked(register FILE *stream)
  14. {
  15. __STDIO_STREAM_VALIDATE(stream);
  16. if ((!__STDIO_STREAM_IS_CUSTOM(stream)) && (stream->__filedes >= 0)) {
  17. return stream->__filedes;
  18. }
  19. __set_errno(EBADF);
  20. return -1;
  21. }
  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