123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #include "_stdio.h"
- #undef fputc
- #undef fputc_unlocked
- #undef putc
- #undef putc_unlocked
- #ifdef __DO_UNLOCKED
- int __fputc_unlocked(int c, register FILE *stream)
- {
- __STDIO_STREAM_VALIDATE(stream);
-
- if (__STDIO_STREAM_CAN_USE_BUFFER_ADD(stream)) {
- __STDIO_STREAM_BUFFER_ADD(stream, ((unsigned char) c));
- return (unsigned char) c;
- }
-
- if (__STDIO_STREAM_IS_NARROW_WRITING(stream)
- || !__STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_NARROW)
- ) {
- if (__STDIO_STREAM_IS_FAKE_VSNPRINTF(stream)) {
- return (unsigned char) c;
- }
- if (__STDIO_STREAM_BUFFER_SIZE(stream)) {
-
- if (!__STDIO_STREAM_BUFFER_WAVAIL(stream)
- && __STDIO_COMMIT_WRITE_BUFFER(stream)
- ) {
- goto BAD;
- }
- #ifdef __UCLIBC_MJN3_ONLY__
- #warning CONSIDER: Should we fail if the commit fails but we now have room?
- #endif
- __STDIO_STREAM_BUFFER_ADD(stream, ((unsigned char) c));
- if (__STDIO_STREAM_IS_LBF(stream)) {
- if ((((unsigned char) c) == '\n')
- && __STDIO_COMMIT_WRITE_BUFFER(stream)) {
-
- __STDIO_STREAM_BUFFER_UNADD(stream);
- goto BAD;
- }
- }
- } else {
-
- unsigned char uc = (unsigned char) c;
- if (! __stdio_WRITE(stream, &uc, 1)) {
- goto BAD;
- }
- }
- return (unsigned char) c;
- }
- BAD:
- return EOF;
- }
- weak_alias(__fputc_unlocked,fputc_unlocked);
- weak_alias(__fputc_unlocked,putc_unlocked);
- #ifndef __UCLIBC_HAS_THREADS__
- weak_alias(__fputc_unlocked,fputc);
- weak_alias(__fputc_unlocked,putc);
- #endif
- #elif defined __UCLIBC_HAS_THREADS__
- int fputc(int c, register FILE *stream)
- {
- if (stream->__user_locking != 0) {
- return __PUTC_UNLOCKED_MACRO(c, stream);
- } else {
- int retval;
- __STDIO_ALWAYS_THREADLOCK(stream);
- retval = __PUTC_UNLOCKED_MACRO(c, stream);
- __STDIO_ALWAYS_THREADUNLOCK(stream);
- return retval;
- }
- }
- weak_alias(fputc,putc);
- #endif
|