1 /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
3 * GNU Library General Public License (LGPL) version 2 or later.
5 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
17 int __fputc_unlocked(int c, register FILE *stream)
19 __STDIO_STREAM_VALIDATE(stream);
21 /* First the fast path. We're good to go if putc macro enabled. */
22 if (__STDIO_STREAM_CAN_USE_BUFFER_ADD(stream)) {
23 __STDIO_STREAM_BUFFER_ADD(stream, ((unsigned char) c));
24 return (unsigned char) c;
27 /* Next quickest... writing and narrow oriented, but macro
28 * disabled and/or buffer is full. */
29 if (__STDIO_STREAM_IS_NARROW_WRITING(stream)
30 || !__STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_NARROW)
32 if (__STDIO_STREAM_IS_FAKE_VSNPRINTF(stream)) {
33 return (unsigned char) c;
36 if (__STDIO_STREAM_BUFFER_SIZE(stream)) { /* Do we have a buffer? */
37 /* The buffer is full and/or the stream is line buffered. */
38 if (!__STDIO_STREAM_BUFFER_WAVAIL(stream) /* Buffer full? */
39 && __STDIO_COMMIT_WRITE_BUFFER(stream) /* Commit failed! */
43 #ifdef __UCLIBC_MJN3_ONLY__
44 #warning CONSIDER: Should we fail if the commit fails but we now have room?
47 __STDIO_STREAM_BUFFER_ADD(stream, ((unsigned char) c));
49 if (__STDIO_STREAM_IS_LBF(stream)) {
50 if ((((unsigned char) c) == '\n')
51 && __STDIO_COMMIT_WRITE_BUFFER(stream)) {
53 __STDIO_STREAM_BUFFER_UNADD(stream); /* Undo the write! */
58 /* NOTE: Do not try to save space by moving uc to the top of
59 * the file, as that dramaticly increases runtime. */
60 unsigned char uc = (unsigned char) c;
61 if (! __stdio_WRITE(stream, &uc, 1)) {
65 return (unsigned char) c;
71 libc_hidden_proto(__fputc_unlocked)
72 libc_hidden_def(__fputc_unlocked)
74 strong_alias(__fputc_unlocked,fputc_unlocked)
76 strong_alias(__fputc_unlocked,putc_unlocked)
77 libc_hidden_proto(putc_unlocked)
78 libc_hidden_def(putc_unlocked)
79 #ifndef __UCLIBC_HAS_THREADS__
80 strong_alias(__fputc_unlocked,fputc)
82 strong_alias(__fputc_unlocked,putc)
83 libc_hidden_proto(putc)
87 #elif defined __UCLIBC_HAS_THREADS__
89 libc_hidden_proto(__fputc_unlocked)
91 int fputc(int c, register FILE *stream)
93 if (stream->__user_locking != 0) {
94 return __PUTC_UNLOCKED_MACRO(c, stream);
97 __STDIO_ALWAYS_THREADLOCK(stream);
98 retval = __PUTC_UNLOCKED_MACRO(c, stream);
99 __STDIO_ALWAYS_THREADUNLOCK(stream);
103 libc_hidden_proto(fputc)
104 libc_hidden_def(fputc)
106 strong_alias(fputc,putc)
107 libc_hidden_proto(putc)
108 libc_hidden_def(putc)