fputs.c 1010 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. /* Note: The standard says fputs returns a nonnegative number on
  9. * success. In this implementation, we return the length of the
  10. * string written on success.
  11. */
  12. #ifdef __DO_UNLOCKED
  13. weak_alias(__fputs_unlocked,fputs_unlocked);
  14. #ifndef __UCLIBC_HAS_THREADS__
  15. weak_alias(__fputs_unlocked,fputs);
  16. #endif
  17. int __fputs_unlocked(register const char * __restrict s,
  18. FILE * __restrict stream)
  19. {
  20. size_t n = strlen(s);
  21. return ((__fwrite_unlocked(s, 1, n, stream) == n) ? n : EOF);
  22. }
  23. #elif defined __UCLIBC_HAS_THREADS__
  24. int fputs(const char * __restrict s, register FILE * __restrict stream)
  25. {
  26. int retval;
  27. __STDIO_AUTO_THREADLOCK_VAR;
  28. __STDIO_AUTO_THREADLOCK(stream);
  29. retval = __fputs_unlocked(s, stream);
  30. __STDIO_AUTO_THREADUNLOCK(stream);
  31. return retval;
  32. }
  33. #endif