| OLD | NEW |
| 1 #include "stdio_impl.h" | 1 #include "stdio_impl.h" |
| 2 #include <string.h> | 2 #include <string.h> |
| 3 | 3 |
| 4 size_t __fwritex(const unsigned char *restrict s, size_t l, FILE *restrict f) | 4 size_t __fwritex(const unsigned char* restrict s, size_t l, FILE* restrict f) { |
| 5 { | 5 size_t i = 0; |
| 6 » size_t i=0; | |
| 7 | 6 |
| 8 » if (!f->wend && __towrite(f)) return 0; | 7 if (!f->wend && __towrite(f)) |
| 8 return 0; |
| 9 | 9 |
| 10 » if (l > f->wend - f->wpos) return f->write(f, s, l); | 10 if (l > f->wend - f->wpos) |
| 11 return f->write(f, s, l); |
| 11 | 12 |
| 12 » if (f->lbf >= 0) { | 13 if (f->lbf >= 0) { |
| 13 » » /* Match /^(.*\n|)/ */ | 14 /* Match /^(.*\n|)/ */ |
| 14 » » for (i=l; i && s[i-1] != '\n'; i--); | 15 for (i = l; i && s[i - 1] != '\n'; i--) |
| 15 » » if (i) { | 16 ; |
| 16 » » » size_t n = f->write(f, s, i); | 17 if (i) { |
| 17 » » » if (n < i) return n; | 18 size_t n = f->write(f, s, i); |
| 18 » » » s += i; | 19 if (n < i) |
| 19 » » » l -= i; | 20 return n; |
| 20 » » } | 21 s += i; |
| 21 » } | 22 l -= i; |
| 23 } |
| 24 } |
| 22 | 25 |
| 23 » memcpy(f->wpos, s, l); | 26 memcpy(f->wpos, s, l); |
| 24 » f->wpos += l; | 27 f->wpos += l; |
| 25 » return l+i; | 28 return l + i; |
| 26 } | 29 } |
| 27 | 30 |
| 28 size_t fwrite(const void *restrict src, size_t size, size_t nmemb, FILE *restric
t f) | 31 size_t fwrite(const void* restrict src, |
| 29 { | 32 size_t size, |
| 30 » size_t k, l = size*nmemb; | 33 size_t nmemb, |
| 31 » if (!size) nmemb = 0; | 34 FILE* restrict f) { |
| 32 » FLOCK(f); | 35 size_t k, l = size * nmemb; |
| 33 » k = __fwritex(src, l, f); | 36 if (!size) |
| 34 » FUNLOCK(f); | 37 nmemb = 0; |
| 35 » return k==l ? nmemb : k/size; | 38 FLOCK(f); |
| 39 k = __fwritex(src, l, f); |
| 40 FUNLOCK(f); |
| 41 return k == l ? nmemb : k / size; |
| 36 } | 42 } |
| 37 | 43 |
| 38 weak_alias(fwrite, fwrite_unlocked); | 44 weak_alias(fwrite, fwrite_unlocked); |
| OLD | NEW |