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.
10 libc_hidden_proto(fwrite_unlocked)
14 size_t fwrite_unlocked(const void * __restrict ptr, size_t size,
15 size_t nmemb, register FILE * __restrict stream)
17 __STDIO_STREAM_VALIDATE(stream);
19 /* Note: If nmbem * size > SIZE_MAX then there is an application
20 * bug since no array can be larger than SIZE_MAX in size. */
22 if ((__STDIO_STREAM_IS_NARROW_WRITING(stream)
23 || !__STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_NARROW))
27 if (nmemb <= (SIZE_MAX / size)) {
28 return __stdio_fwrite((const unsigned char *) ptr,
29 size*nmemb, stream) / size;
32 __STDIO_STREAM_SET_ERROR(stream);
38 libc_hidden_def(fwrite_unlocked)
40 #ifndef __UCLIBC_HAS_THREADS__
41 strong_alias(fwrite_unlocked,fwrite)
42 libc_hidden_proto(fwrite)
43 libc_hidden_def(fwrite)
46 #elif defined __UCLIBC_HAS_THREADS__
48 size_t fwrite(const void * __restrict ptr, size_t size,
49 size_t nmemb, register FILE * __restrict stream)
52 __STDIO_AUTO_THREADLOCK_VAR;
54 __STDIO_AUTO_THREADLOCK(stream);
56 retval = fwrite_unlocked(ptr, size, nmemb, stream);
58 __STDIO_AUTO_THREADUNLOCK(stream);
62 libc_hidden_proto(fwrite)
63 libc_hidden_def(fwrite)