1 /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
3 * GNU Library General Public License (LGPL) version 2 or later.
5 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
13 size_t fwrite_unlocked(const void * __restrict ptr
, size_t size
,
14 size_t nmemb
, register FILE * __restrict stream
)
16 __STDIO_STREAM_VALIDATE(stream
);
18 /* Note: If nmbem * size > SIZE_MAX then there is an application
19 * bug since no array can be larger than SIZE_MAX in size. */
21 if ((__STDIO_STREAM_IS_NARROW_WRITING(stream
)
22 || !__STDIO_STREAM_TRANS_TO_WRITE(stream
, __FLAG_NARROW
))
26 if (nmemb
<= (SIZE_MAX
/ size
)) {
27 return __stdio_fwrite((const unsigned char *) ptr
,
28 size
*nmemb
, stream
) / size
;
31 __STDIO_STREAM_SET_ERROR(stream
);
37 libc_hidden_def(fwrite_unlocked
)
39 #ifndef __UCLIBC_HAS_THREADS__
40 strong_alias(fwrite_unlocked
,fwrite
)
41 libc_hidden_def(fwrite
)
44 #elif defined __UCLIBC_HAS_THREADS__
46 size_t fwrite(const void * __restrict ptr
, size_t size
,
47 size_t nmemb
, register FILE * __restrict stream
)
50 __STDIO_AUTO_THREADLOCK_VAR
;
52 __STDIO_AUTO_THREADLOCK(stream
);
54 retval
= fwrite_unlocked(ptr
, size
, nmemb
, stream
);
56 __STDIO_AUTO_THREADUNLOCK(stream
);
60 libc_hidden_def(fwrite
)