fileno.c 959 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 attribute_hidden __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. hidden_weak_alias(__fileno_unlocked,__fileno)
  21. weak_alias(__fileno_unlocked,fileno)
  22. #endif
  23. #elif defined __UCLIBC_HAS_THREADS__
  24. int attribute_hidden __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. strong_alias(__fileno,fileno)
  34. #endif