2 * Copyright (c) 1990 The Regents of the University of California.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 <<fwrite>>---write array elements
27 size_t fwrite(const void *<[buf]>, size_t <[size]>,
28 size_t <[count]>, FILE *<[fp]>);
32 size_t fwrite(<[buf]>, <[size]>, <[count]>, <[fp]>)
39 <<fwrite>> attempts to copy, starting from the memory location
40 <[buf]>, <[count]> elements (each of size <[size]>) into the file or
41 stream identified by <[fp]>. <<fwrite>> may copy fewer elements than
42 <[count]> if an error intervenes.
44 <<fwrite>> also advances the file position indicator (if any) for
45 <[fp]> by the number of @emph{characters} actually written.
48 If <<fwrite>> succeeds in writing all the elements you specify, the
49 result is the same as the argument <[count]>. In any event, the
50 result is the number of complete elements that <<fwrite>> copied to
54 ANSI C requires <<fwrite>>.
56 Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
57 <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
60 #if defined(LIBC_SCCS) && !defined(lint)
61 static char sccsid
[] = "%W% (Berkeley) %G%";
62 #endif /* LIBC_SCCS and not lint */
75 * Write `count' objects (each size `size') from memory to the given file.
76 * Return the number of whole objects written.
80 _DEFUN (fwrite
, (buf
, size
, count
, fp
),
91 uio
.uio_resid
= iov
.iov_len
= n
= count
* size
;
96 * The usual case is success (__sfvwrite returns 0);
97 * skip the divide if this happens, since divides are
98 * generally slow and since this occurs whenever size==0.
102 if (__sfvwrite (fp
, &uio
) == 0)
108 return (n
- uio
.uio_resid
) / size
;