OSDN Git Service

hidden_def/hidden_proto: convert all users (I hope) termios split, add some missing...
[uclinux-h8/uClibc.git] / libc / stdio / fwrite.c
1 /* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
2  *
3  * GNU Library General Public License (LGPL) version 2 or later.
4  *
5  * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
6  */
7
8 #include "_stdio.h"
9
10 libc_hidden_proto(fwrite_unlocked)
11
12 #ifdef __DO_UNLOCKED
13
14 size_t fwrite_unlocked(const void * __restrict ptr, size_t size,
15                                                  size_t nmemb, register FILE * __restrict stream)
16 {
17         __STDIO_STREAM_VALIDATE(stream);
18
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. */
21
22         if ((__STDIO_STREAM_IS_NARROW_WRITING(stream)
23                  || !__STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_NARROW))
24                 && size && nmemb
25                 ) {
26
27                 if (nmemb <= (SIZE_MAX / size)) {
28                         return __stdio_fwrite((const unsigned char *) ptr,
29                                                                   size*nmemb, stream) / size;
30                 }
31
32                 __STDIO_STREAM_SET_ERROR(stream);
33                 __set_errno(EINVAL);
34         }
35
36         return 0;
37 }
38 libc_hidden_def(fwrite_unlocked)
39
40 #ifndef __UCLIBC_HAS_THREADS__
41 strong_alias(fwrite_unlocked,fwrite)
42 libc_hidden_proto(fwrite)
43 libc_hidden_def(fwrite)
44 #endif
45
46 #elif defined __UCLIBC_HAS_THREADS__
47
48 size_t fwrite(const void * __restrict ptr, size_t size,
49                           size_t nmemb, register FILE * __restrict stream)
50 {
51         size_t retval;
52         __STDIO_AUTO_THREADLOCK_VAR;
53
54         __STDIO_AUTO_THREADLOCK(stream);
55
56         retval = fwrite_unlocked(ptr, size, nmemb, stream);
57
58         __STDIO_AUTO_THREADUNLOCK(stream);
59
60         return retval;
61 }
62 libc_hidden_proto(fwrite)
63 libc_hidden_def(fwrite)
64
65 #endif