2 * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * By using this file, you agree to the terms and conditions set
11 * forth in the LICENSE file which can be found at the top level of
12 * the sendmail distribution.
15 #pragma ident "%Z%%M% %I% %E% SMI"
18 SM_RCSID("@(#)$Id: fwrite.c,v 1.22 2001/04/03 01:46:40 ca Exp $")
21 #include <sm/assert.h>
26 ** SM_IO_WRITE -- write to a file pointer
29 ** fp -- file pointer writing to
30 ** timeout -- time to complete the write
31 ** buf -- location of data to be written
32 ** size -- number of bytes to be written
35 ** Failure: returns 0 _and_ sets errno
36 ** Success: returns >=0 with errno unchanged, where the
37 ** number returned is the number of bytes written.
41 sm_io_write(fp
, timeout
, buf
, size
)
50 SM_REQUIRE_ISA(fp
, SmFileMagic
);
52 if (fp
->f_write
== NULL
)
58 iov
.iov_base
= (void *) buf
;
59 uio
.uio_resid
= iov
.iov_len
= size
;
63 /* The usual case is success (sm_fvwrite returns 0) */
64 if (sm_fvwrite(fp
, timeout
, &uio
) == 0)
67 /* else return number of bytes actually written */
68 return size
- uio
.uio_resid
;