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. int __fputs_unlocked(register const char * __restrict s,
  14. FILE * __restrict stream)
  15. {
  16. size_t n = strlen(s);
  17. return ((__fwrite_unlocked(s, 1, n, stream) == n) ? n : EOF);
  18. }
  19. weak_alias(__fputs_unlocked,fputs_unlocked);
  20. #ifndef __UCLIBC_HAS_THREADS__
  21. weak_alias(__fputs_unlocked,fputs);
  22. #endif
  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