netinet/in.h: add IPPROTO_MH
[uclibc-ng.git] / libc / stdio / fwrite.c
blob71793ff260a13c453c0d0e3bce6c5741fec620b4
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.
6 */
8 #include "_stdio.h"
11 #ifdef __DO_UNLOCKED
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))
23 && size && nmemb
24 ) {
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);
32 __set_errno(EINVAL);
35 return 0;
37 libc_hidden_def(fwrite_unlocked)
39 #ifndef __UCLIBC_HAS_THREADS__
40 strong_alias(fwrite_unlocked,fwrite)
41 libc_hidden_def(fwrite)
42 #endif
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)
49 size_t retval;
50 __STDIO_AUTO_THREADLOCK_VAR;
52 __STDIO_AUTO_THREADLOCK(stream);
54 retval = fwrite_unlocked(ptr, size, nmemb, stream);
56 __STDIO_AUTO_THREADUNLOCK(stream);
58 return retval;
60 libc_hidden_def(fwrite)
62 #endif