Commit | Line | Data |
---|---|---|
411867e7 KB |
1 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * This code is derived from software contributed to Berkeley by | |
6 | * Chris Torek. | |
7 | * | |
8 | * %sccs.include.redist.c% | |
586c39b1 DF |
9 | */ |
10 | ||
2ce81398 | 11 | #if defined(LIBC_SCCS) && !defined(lint) |
cb631443 | 12 | static char sccsid[] = "@(#)fwrite.c 5.5 (Berkeley) %G%"; |
411867e7 | 13 | #endif /* LIBC_SCCS and not lint */ |
586c39b1 | 14 | |
411867e7 | 15 | #include <stdio.h> |
411867e7 KB |
16 | #include "local.h" |
17 | #include "fvwrite.h" | |
29468241 | 18 | |
411867e7 KB |
19 | /* |
20 | * Write `count' objects (each size `size') from memory to the given file. | |
21 | * Return the number of whole objects written. | |
22 | */ | |
23 | fwrite(buf, size, count, fp) | |
d25ccb19 | 24 | const void *buf; |
411867e7 KB |
25 | size_t size, count; |
26 | FILE *fp; | |
29468241 | 27 | { |
411867e7 KB |
28 | size_t n; |
29 | struct __suio uio; | |
30 | struct __siov iov; | |
31 | ||
d25ccb19 | 32 | iov.iov_base = (void *)buf; |
411867e7 KB |
33 | uio.uio_resid = iov.iov_len = n = count * size; |
34 | uio.uio_iov = &iov; | |
35 | uio.uio_iovcnt = 1; | |
29468241 | 36 | |
411867e7 KB |
37 | /* |
38 | * The usual case is success (__sfvwrite returns 0); | |
39 | * skip the divide if this happens, since divides are | |
40 | * generally slow and since this occurs whenever size==0. | |
41 | */ | |
42 | if (__sfvwrite(fp, &uio) == 0) | |
43 | return (count); | |
44 | return ((n - uio.uio_resid) / size); | |
29468241 | 45 | } |