puts.c 918 B

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