2N/A#ifndef LINT
2N/Astatic const char rcsid[] = "$Id: writev.c,v 1.3 2005/04/27 04:56:13 sra Exp $";
2N/A#endif
2N/A
2N/A#include "port_before.h"
2N/A
2N/A#include <sys/types.h>
2N/A#include <sys/uio.h>
2N/A#include <sys/stat.h>
2N/A#include <sys/socket.h>
2N/A
2N/A#include "port_after.h"
2N/A
2N/A#ifndef NEED_WRITEV
2N/Aint __bindcompat_writev;
2N/A#else
2N/A
2N/A#ifdef _CRAY
2N/A#define OWN_WRITEV
2N/Aint
2N/A__writev(int fd, struct iovec *iov, int iovlen)
2N/A{
2N/A struct stat statbuf;
2N/A
2N/A if (fstat(fd, &statbuf) < 0)
2N/A return (-1);
2N/A
2N/A /*
2N/A * Allow for atomic writes to network.
2N/A */
2N/A if (statbuf.st_mode & S_IFSOCK) {
2N/A struct msghdr mesg;
2N/A
2N/A memset(&mesg, 0, sizeof(mesg));
2N/A mesg.msg_name = 0;
2N/A mesg.msg_namelen = 0;
2N/A mesg.msg_iov = iov;
2N/A mesg.msg_iovlen = iovlen;
2N/A mesg.msg_accrights = 0;
2N/A mesg.msg_accrightslen = 0;
2N/A return (sendmsg(fd, &mesg, 0));
2N/A } else {
2N/A struct iovec *tv;
2N/A int i, rcode = 0, count = 0;
2N/A
2N/A for (i = 0, tv = iov; i <= iovlen; tv++) {
2N/A rcode = write(fd, tv->iov_base, tv->iov_len);
2N/A
2N/A if (rcode < 0)
2N/A break;
2N/A
2N/A count += rcode;
2N/A }
2N/A
2N/A if (count == 0)
2N/A return (rcode);
2N/A else
2N/A return (count);
2N/A }
2N/A}
2N/A
2N/A#else /*_CRAY*/
2N/A
2N/Aint
2N/A__writev(fd, vp, vpcount)
2N/A int fd;
2N/A const struct iovec *vp;
2N/A int vpcount;
2N/A{
2N/A int count = 0;
2N/A
2N/A while (vpcount-- > 0) {
2N/A int written = write(fd, vp->iov_base, vp->iov_len);
2N/A
2N/A if (written < 0)
2N/A return (-1);
2N/A count += written;
2N/A if (written != vp->iov_len)
2N/A break;
2N/A vp++;
2N/A }
2N/A return (count);
2N/A}
2N/A
2N/A#endif /*_CRAY*/
2N/A
2N/A#endif /*NEED_WRITEV*/
2N/A
2N/A/*! \file */