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