8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / sendmail / libsm / fwrite.c
blobf99eab1bb2651693523259f8f70384440cf36994
1 /*
2 * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
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
8 * Chris Torek.
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"
17 #include <sm/gen.h>
18 SM_RCSID("@(#)$Id: fwrite.c,v 1.22 2001/04/03 01:46:40 ca Exp $")
19 #include <errno.h>
20 #include <sm/io.h>
21 #include <sm/assert.h>
22 #include "local.h"
23 #include "fvwrite.h"
26 ** SM_IO_WRITE -- write to a file pointer
28 ** Parameters:
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
34 ** Result:
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.
40 size_t
41 sm_io_write(fp, timeout, buf, size)
42 SM_FILE_T *fp;
43 int timeout;
44 const void *buf;
45 size_t size;
47 struct sm_uio uio;
48 struct sm_iov iov;
50 SM_REQUIRE_ISA(fp, SmFileMagic);
52 if (fp->f_write == NULL)
54 errno = ENODEV;
55 return 0;
58 iov.iov_base = (void *) buf;
59 uio.uio_resid = iov.iov_len = size;
60 uio.uio_iov = &iov;
61 uio.uio_iovcnt = 1;
63 /* The usual case is success (sm_fvwrite returns 0) */
64 if (sm_fvwrite(fp, timeout, &uio) == 0)
65 return size;
67 /* else return number of bytes actually written */
68 return size - uio.uio_resid;