Import sendmail 8.13.7
[dragonfly.git] / contrib / sendmail-8.13.7 / libsm / fwrite.c
blob372f75dfe9bcef2a697d9dd8f8ccab0a0c0aaa5d
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 #include <sm/gen.h>
16 SM_RCSID("@(#)$Id: fwrite.c,v 1.24 2001/09/11 04:04:48 gshapiro Exp $")
17 #include <errno.h>
18 #include <sm/io.h>
19 #include <sm/assert.h>
20 #include "local.h"
21 #include "fvwrite.h"
24 ** SM_IO_WRITE -- write to a file pointer
26 ** Parameters:
27 ** fp -- file pointer writing to
28 ** timeout -- time to complete the write
29 ** buf -- location of data to be written
30 ** size -- number of bytes to be written
32 ** Result:
33 ** Failure: returns 0 _and_ sets errno
34 ** Success: returns >=0 with errno unchanged, where the
35 ** number returned is the number of bytes written.
38 size_t
39 sm_io_write(fp, timeout, buf, size)
40 SM_FILE_T *fp;
41 int timeout;
42 const void *buf;
43 size_t size;
45 struct sm_uio uio;
46 struct sm_iov iov;
48 SM_REQUIRE_ISA(fp, SmFileMagic);
50 if (fp->f_write == NULL)
52 errno = ENODEV;
53 return 0;
56 iov.iov_base = (void *) buf;
57 uio.uio_resid = iov.iov_len = size;
58 uio.uio_iov = &iov;
59 uio.uio_iovcnt = 1;
61 /* The usual case is success (sm_fvwrite returns 0) */
62 if (sm_fvwrite(fp, timeout, &uio) == 0)
63 return size;
65 /* else return number of bytes actually written */
66 return size - uio.uio_resid;