size_t _fwrite(const void *buf, size_t count, FILE *file) { struct _IO_file_pvt *f = stdio_pvt(file); size_t bytes = 0; size_t pf_len, pu_len; const char *p = buf; const char *q; /* We divide the data into two chunks, flushed (pf) and unflushed (pu) depending on buffering mode and contents. */ switch (f->bufmode) { case _IOFBF: pf_len = 0; break; case _IOLBF: q = memrchr(p, '\n', count); pf_len = q ? q - p + 1 : 0; break; case _IONBF: default: pf_len = count; break; } if (pf_len) { bytes = fwrite_noflush(p, pf_len, f); p += bytes; if (__fflush(f) || bytes != pf_len) return bytes; } pu_len = count - pf_len; if (pu_len) bytes += fwrite_noflush(p, pu_len, f); return bytes; }
size_t _fwrite(const void *buf, size_t count, FILE *f) { size_t bytes = 0; size_t pf_len, pu_len; const char *p = buf; /* We divide the data into two chunks, flushed (pf) and unflushed (pu) depending on buffering mode and contents. */ if (f->flags & _IO_FILE_FLAG_UNBUF) { pf_len = 0; pu_len = count; } else if (f->flags & _IO_FILE_FLAG_LINE_BUF) { pf_len = count; pu_len = 0; while (pf_len && p[pf_len-1] != '\n') { pf_len--; pu_len++; } } else { pf_len = 0; pu_len = count; } if (pf_len) { bytes = fwrite_noflush(p, pf_len, f); p += bytes; if (fflush(f) || bytes != pf_len) return bytes; } if (pu_len) bytes += fwrite_noflush(p, pu_len, f); return bytes; }