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.
18 int __fputc_unlocked(int c, register FILE *stream)
20 __STDIO_STREAM_VALIDATE(stream);
22 /* First the fast path. We're good to go if putc macro enabled. */
23 if (__STDIO_STREAM_CAN_USE_BUFFER_ADD(stream)) {
24 __STDIO_STREAM_BUFFER_ADD(stream, ((unsigned char) c));
25 return (unsigned char) c;
28 /* Next quickest... writing and narrow oriented, but macro
29 * disabled and/or buffer is full. */
30 if (__STDIO_STREAM_IS_NARROW_WRITING(stream)
31 || !__STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_NARROW)
33 if (__STDIO_STREAM_IS_FAKE_VSNPRINTF(stream)) {
34 return (unsigned char) c;
37 if (__STDIO_STREAM_BUFFER_SIZE(stream)) { /* Do we have a buffer? */
38 /* The buffer is full and/or the stream is line buffered. */
39 if (!__STDIO_STREAM_BUFFER_WAVAIL(stream) /* Buffer full? */
40 && __STDIO_COMMIT_WRITE_BUFFER(stream) /* Commit failed! */
44 #ifdef __UCLIBC_MJN3_ONLY__
45 #warning CONSIDER: Should we fail if the commit fails but we now have room?
48 __STDIO_STREAM_BUFFER_ADD(stream, ((unsigned char) c));
50 if (__STDIO_STREAM_IS_LBF(stream)) {
51 if ((((unsigned char) c) == '\n')
52 && __STDIO_COMMIT_WRITE_BUFFER(stream)) {
54 __STDIO_STREAM_BUFFER_UNADD(stream); /* Undo the write! */
59 /* NOTE: Do not try to save space by moving uc to the top of
60 * the file, as that dramaticly increases runtime. */
61 unsigned char uc = (unsigned char) c;
62 if (! __stdio_WRITE(stream, &uc, 1)) {
66 return (unsigned char) c;
72 libc_hidden_def(__fputc_unlocked)
74 strong_alias(__fputc_unlocked,fputc_unlocked)
76 strong_alias(__fputc_unlocked,putc_unlocked)
77 #ifndef __UCLIBC_HAS_THREADS__
78 strong_alias(__fputc_unlocked,fputc)
79 libc_hidden_def(fputc)
81 strong_alias(__fputc_unlocked,putc)
84 #elif defined __UCLIBC_HAS_THREADS__
86 int fputc(int c, register FILE *stream)
88 if (stream->__user_locking != 0) {
89 return __PUTC_UNLOCKED_MACRO(c, stream);
92 __STDIO_ALWAYS_THREADLOCK(stream);
93 retval = __PUTC_UNLOCKED_MACRO(c, stream);
94 __STDIO_ALWAYS_THREADUNLOCK(stream);
98 libc_hidden_def(fputc)
100 strong_alias(fputc,putc)