puts.c 939 B

123456789101112131415161718192021222324252627282930313233343536
  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. libc_hidden_proto(__fputc_unlocked)
  9. libc_hidden_proto(fputs_unlocked)
  10. int puts(register const char * __restrict s)
  11. {
  12. register FILE *stream = stdout; /* This helps bcc optimize. */
  13. int n;
  14. __STDIO_AUTO_THREADLOCK_VAR;
  15. __STDIO_AUTO_THREADLOCK(stream);
  16. /* Note: Don't try to optimize by switching to FBF until the newline.
  17. * If the string itself contained a newline a write error occurred,
  18. * then we could have a newline in the buffer of an LBF stream. */
  19. /* Note: Nonportable as fputs need only return nonnegative on success. */
  20. if ((n = fputs_unlocked(s, stream)) != EOF) {
  21. ++n;
  22. if (__fputc_unlocked('\n', stream) == EOF) {
  23. n = EOF;
  24. }
  25. }
  26. __STDIO_AUTO_THREADUNLOCK(stream);
  27. return n;
  28. }