limit the configurable default stack/guard size for threads
[musl.git] / src / stdio / fwrite.c
blob7a567b2c55a94b30288444bd93f6fc48fff7e433
1 #include "stdio_impl.h"
2 #include <string.h>
4 size_t __fwritex(const unsigned char *restrict s, size_t l, FILE *restrict f)
6 size_t i=0;
8 if (!f->wend && __towrite(f)) return 0;
10 if (l > f->wend - f->wpos) return f->write(f, s, l);
12 if (f->lbf >= 0) {
13 /* Match /^(.*\n|)/ */
14 for (i=l; i && s[i-1] != '\n'; i--);
15 if (i) {
16 size_t n = f->write(f, s, i);
17 if (n < i) return n;
18 s += i;
19 l -= i;
23 memcpy(f->wpos, s, l);
24 f->wpos += l;
25 return l+i;
28 size_t fwrite(const void *restrict src, size_t size, size_t nmemb, FILE *restrict f)
30 size_t k, l = size*nmemb;
31 if (!size) nmemb = 0;
32 FLOCK(f);
33 k = __fwritex(src, l, f);
34 FUNLOCK(f);
35 return k==l ? nmemb : k/size;
38 weak_alias(fwrite, fwrite_unlocked);