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! */
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
)) {
51 __STDIO_STREAM_BUFFER_UNADD(stream
); /* Undo the write! */
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)) {
63 return (unsigned char) c
;
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
)
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
);
89 __STDIO_ALWAYS_THREADLOCK(stream
);
90 retval
= __PUTC_UNLOCKED_MACRO(c
, stream
);
91 __STDIO_ALWAYS_THREADUNLOCK(stream
);
95 libc_hidden_def(fputc
)
97 strong_alias(fputc
,putc
)