puts.c 870 B

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