netinet/in.h: add IPPROTO_MH
[uclibc-ng.git] / libc / stdio / fputc.c
blobd4e5d25288bc624648ebabc2b221e6734cd0d37d
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.
6 */
8 #include "_stdio.h"
10 #undef fputc
11 #undef fputc_unlocked
12 #undef putc
13 #undef putc_unlocked
16 #ifdef __DO_UNLOCKED
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)
32 ) {
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! */
41 ) {
42 goto BAD;
45 __STDIO_STREAM_BUFFER_ADD(stream, ((unsigned char) c));
47 if (__STDIO_STREAM_IS_LBF(stream)) {
48 if ((((unsigned char) c) == '\n')
49 && __STDIO_COMMIT_WRITE_BUFFER(stream)) {
50 /* Commit failed! */
51 __STDIO_STREAM_BUFFER_UNADD(stream); /* Undo the write! */
52 goto BAD;
55 } else {
56 /* NOTE: Do not try to save space by moving uc to the top of
57 * the file, as that dramaticly increases runtime. */
58 unsigned char uc = (unsigned char) c;
59 if (! __stdio_WRITE(stream, &uc, 1)) {
60 goto BAD;
63 return (unsigned char) c;
66 BAD:
67 return EOF;
69 libc_hidden_def(__fputc_unlocked)
71 strong_alias(__fputc_unlocked,fputc_unlocked)
73 strong_alias(__fputc_unlocked,putc_unlocked)
74 #ifndef __UCLIBC_HAS_THREADS__
75 strong_alias(__fputc_unlocked,fputc)
76 libc_hidden_def(fputc)
78 strong_alias(__fputc_unlocked,putc)
79 #endif
81 #elif defined __UCLIBC_HAS_THREADS__
83 int fputc(int c, register FILE *stream)
85 if (stream->__user_locking != 0) {
86 return __PUTC_UNLOCKED_MACRO(c, stream);
87 } else {
88 int retval;
89 __STDIO_ALWAYS_THREADLOCK(stream);
90 retval = __PUTC_UNLOCKED_MACRO(c, stream);
91 __STDIO_ALWAYS_THREADUNLOCK(stream);
92 return retval;
95 libc_hidden_def(fputc)
97 strong_alias(fputc,putc)
99 #endif