123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #include "_stdio.h"
- size_t attribute_hidden __stdio_WRITE(register FILE *stream,
- register const unsigned char *buf, size_t bufsize)
- {
- size_t todo;
- ssize_t rv, stodo;
- __STDIO_STREAM_VALIDATE(stream);
- assert(stream->__filedes >= -1);
- assert(__STDIO_STREAM_IS_WRITING(stream));
- assert(!__STDIO_STREAM_BUFFER_WUSED(stream));
- todo = bufsize;
- do {
- if (todo == 0) {
- __STDIO_STREAM_VALIDATE(stream);
- return bufsize;
- }
- stodo = (todo <= SSIZE_MAX) ? todo : SSIZE_MAX;
- if ((rv = __WRITE(stream, buf, stodo)) >= 0) {
- #ifdef __UCLIBC_MJN3_ONLY__
- #warning TODO: Make custom stream write return check optional.
- #endif
- #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- assert(rv <= stodo);
- if (rv > stodo) {
- }
- #endif
- todo -= rv;
- buf += rv;
- } else
- #ifdef __UCLIBC_MJN3_ONLY__
- #warning EINTR?
- #endif
- {
- __STDIO_STREAM_SET_ERROR(stream);
- #ifdef __STDIO_BUFFERS
- if ((stodo = __STDIO_STREAM_BUFFER_SIZE(stream)) != 0) {
- unsigned char *s;
- if (stodo > todo) {
- stodo = todo;
- }
- s = stream->__bufstart;
- do {
- if (((*s = *buf) == '\n')
- && __STDIO_STREAM_IS_LBF(stream)
- ) {
- break;
- }
- ++s;
- ++buf;
- } while (--stodo);
- stream->__bufpos = s;
- todo -= (s - stream->__bufstart);
- }
- #endif
- __STDIO_STREAM_VALIDATE(stream);
- return bufsize - todo;
- }
- } while (1);
- }
|