146089Sbostic /*- 246089Sbostic * Copyright (c) 1990 The Regents of the University of California. 346089Sbostic * All rights reserved. 446089Sbostic * 546089Sbostic * This code is derived from software contributed to Berkeley by 646089Sbostic * Chris Torek. 746089Sbostic * 846089Sbostic * %sccs.include.redist.c% 921408Sdist */ 1021408Sdist 1126655Sdonn #if defined(LIBC_SCCS) && !defined(lint) 12*50964Sbostic static char sccsid[] = "@(#)fwrite.c 5.6 (Berkeley) 09/03/91"; 1346089Sbostic #endif /* LIBC_SCCS and not lint */ 1421408Sdist 1546089Sbostic #include <stdio.h> 1646089Sbostic #include "local.h" 1746089Sbostic #include "fvwrite.h" 1816550Skarels 1946089Sbostic /* 2046089Sbostic * Write `count' objects (each size `size') from memory to the given file. 2146089Sbostic * Return the number of whole objects written. 2246089Sbostic */ 23*50964Sbostic size_t 2446089Sbostic fwrite(buf, size, count, fp) 2546271Storek const void *buf; 2646089Sbostic size_t size, count; 2746089Sbostic FILE *fp; 2816550Skarels { 2946089Sbostic size_t n; 3046089Sbostic struct __suio uio; 3146089Sbostic struct __siov iov; 3216550Skarels 3346271Storek iov.iov_base = (void *)buf; 3446089Sbostic uio.uio_resid = iov.iov_len = n = count * size; 3546089Sbostic uio.uio_iov = &iov; 3646089Sbostic uio.uio_iovcnt = 1; 3746089Sbostic 3846089Sbostic /* 3946089Sbostic * The usual case is success (__sfvwrite returns 0); 4046089Sbostic * skip the divide if this happens, since divides are 4146089Sbostic * generally slow and since this occurs whenever size==0. 4246089Sbostic */ 4346089Sbostic if (__sfvwrite(fp, &uio) == 0) 4446089Sbostic return (count); 4546089Sbostic return ((n - uio.uio_resid) / size); 4616550Skarels } 47