1N/A/*
1N/A * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
1N/A * All rights reserved.
1N/A * Copyright (c) 1990, 1993
1N/A * The Regents of the University of California. All rights reserved.
1N/A *
1N/A * This code is derived from software contributed to Berkeley by
1N/A * Chris Torek.
1N/A *
1N/A * By using this file, you agree to the terms and conditions set
1N/A * forth in the LICENSE file which can be found at the top level of
1N/A * the sendmail distribution.
1N/A */
1N/A
1N/A#pragma ident "%Z%%M% %I% %E% SMI"
1N/A
1N/A#include <sm/gen.h>
1N/ASM_RCSID("@(#)$Id: fwrite.c,v 1.22 2001/04/03 01:46:40 ca Exp $")
1N/A#include <errno.h>
1N/A#include <sm/io.h>
1N/A#include <sm/assert.h>
1N/A#include "local.h"
1N/A#include "fvwrite.h"
1N/A
1N/A/*
1N/A** SM_IO_WRITE -- write to a file pointer
1N/A**
1N/A** Parameters:
1N/A** fp -- file pointer writing to
1N/A** timeout -- time to complete the write
1N/A** buf -- location of data to be written
1N/A** size -- number of bytes to be written
1N/A**
1N/A** Result:
1N/A** Failure: returns 0 _and_ sets errno
1N/A** Success: returns >=0 with errno unchanged, where the
1N/A** number returned is the number of bytes written.
1N/A*/
1N/A
1N/Asize_t
1N/Asm_io_write(fp, timeout, buf, size)
1N/A SM_FILE_T *fp;
1N/A int timeout;
1N/A const void *buf;
1N/A size_t size;
1N/A{
1N/A struct sm_uio uio;
1N/A struct sm_iov iov;
1N/A
1N/A SM_REQUIRE_ISA(fp, SmFileMagic);
1N/A
1N/A if (fp->f_write == NULL)
1N/A {
1N/A errno = ENODEV;
1N/A return 0;
1N/A }
1N/A
1N/A iov.iov_base = (void *) buf;
1N/A uio.uio_resid = iov.iov_len = size;
1N/A uio.uio_iov = &iov;
1N/A uio.uio_iovcnt = 1;
1N/A
1N/A /* The usual case is success (sm_fvwrite returns 0) */
1N/A if (sm_fvwrite(fp, timeout, &uio) == 0)
1N/A return size;
1N/A
1N/A /* else return number of bytes actually written */
1N/A return size - uio.uio_resid;
1N/A}