1fwrite(3C) Standard C Library Functions fwrite(3C)
2
3
4
6 fwrite - binary output
7
9 #include <stdio.h>
10
11 size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);
12
13
15 The fwrite() function writes, from the array pointed to by ptr, up to
16 nitems elements whose size is specified by size, to the stream pointed
17 to by stream. For each object, size calls are made to the fputc(3C)
18 function, taking the values (in order) from an array of unsigned char
19 exactly overlaying the object. The file-position indicator for the
20 stream (if defined) is advanced by the number of bytes successfully
21 written. If an error occurs, the resulting value of the file-position
22 indicator for the stream is unspecified.
23
24
25 The st_ctime and st_mtime fields of the file will be marked for update
26 between the successful execution of fwrite() and the next successful
27 completion of a call to fflush(3C) or fclose(3C) on the same stream or
28 a call to exit(2) or abort(3C).
29
31 The fwrite() function returns the number of elements successfully writ‐
32 ten, which might be less than nitems if a write error is encountered.
33 If size or nitems is 0, fwrite() returns 0 and the state of the stream
34 remains unchanged. Otherwise, if a write error occurs, the error indi‐
35 cator for the stream is set and errno is set to indicate the error.
36
38 Refer to fputc(3C).
39
41 Because of possible differences in element length and byte ordering,
42 files written using fwrite() are application-dependent, and possibly
43 cannot be read using fread(3C) by a different application or by the
44 same application on a different processor.
45
47 See attributes(5) for descriptions of the following attributes:
48
49
50
51
52 ┌─────────────────────────────┬─────────────────────────────┐
53 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
54 ├─────────────────────────────┼─────────────────────────────┤
55 │Interface Stability │Standard │
56 ├─────────────────────────────┼─────────────────────────────┤
57 │MT-Level │MT-Safe │
58 └─────────────────────────────┴─────────────────────────────┘
59
61 write(2), fclose(3C), ferror(3C), fopen(3C), fread(3C), getc(3C),
62 gets(3C), printf(3C), putc(3C), puts(3C), attributes(5), standards(5)
63
64
65
66SunOS 5.11 24 Jul 2002 fwrite(3C)