10Sstevel@tonic-gate #ifndef LINT
2*11038SRao.Shoaib@Sun.COM static const char rcsid[] = "$Id: writev.c,v 1.3 2005/04/27 04:56:13 sra Exp $";
30Sstevel@tonic-gate #endif
40Sstevel@tonic-gate
50Sstevel@tonic-gate #include "port_before.h"
60Sstevel@tonic-gate
70Sstevel@tonic-gate #include <sys/types.h>
80Sstevel@tonic-gate #include <sys/uio.h>
90Sstevel@tonic-gate #include <sys/stat.h>
100Sstevel@tonic-gate #include <sys/socket.h>
110Sstevel@tonic-gate
120Sstevel@tonic-gate #include "port_after.h"
130Sstevel@tonic-gate
140Sstevel@tonic-gate #ifndef NEED_WRITEV
150Sstevel@tonic-gate int __bindcompat_writev;
160Sstevel@tonic-gate #else
170Sstevel@tonic-gate
180Sstevel@tonic-gate #ifdef _CRAY
190Sstevel@tonic-gate #define OWN_WRITEV
200Sstevel@tonic-gate int
__writev(int fd,struct iovec * iov,int iovlen)210Sstevel@tonic-gate __writev(int fd, struct iovec *iov, int iovlen)
220Sstevel@tonic-gate {
230Sstevel@tonic-gate struct stat statbuf;
240Sstevel@tonic-gate
250Sstevel@tonic-gate if (fstat(fd, &statbuf) < 0)
260Sstevel@tonic-gate return (-1);
270Sstevel@tonic-gate
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate * Allow for atomic writes to network.
300Sstevel@tonic-gate */
31*11038SRao.Shoaib@Sun.COM if (statbuf.st_mode & S_IFSOCK) {
320Sstevel@tonic-gate struct msghdr mesg;
330Sstevel@tonic-gate
340Sstevel@tonic-gate memset(&mesg, 0, sizeof(mesg));
350Sstevel@tonic-gate mesg.msg_name = 0;
360Sstevel@tonic-gate mesg.msg_namelen = 0;
370Sstevel@tonic-gate mesg.msg_iov = iov;
380Sstevel@tonic-gate mesg.msg_iovlen = iovlen;
390Sstevel@tonic-gate mesg.msg_accrights = 0;
400Sstevel@tonic-gate mesg.msg_accrightslen = 0;
410Sstevel@tonic-gate return (sendmsg(fd, &mesg, 0));
420Sstevel@tonic-gate } else {
430Sstevel@tonic-gate struct iovec *tv;
440Sstevel@tonic-gate int i, rcode = 0, count = 0;
450Sstevel@tonic-gate
460Sstevel@tonic-gate for (i = 0, tv = iov; i <= iovlen; tv++) {
470Sstevel@tonic-gate rcode = write(fd, tv->iov_base, tv->iov_len);
480Sstevel@tonic-gate
490Sstevel@tonic-gate if (rcode < 0)
500Sstevel@tonic-gate break;
510Sstevel@tonic-gate
520Sstevel@tonic-gate count += rcode;
530Sstevel@tonic-gate }
540Sstevel@tonic-gate
550Sstevel@tonic-gate if (count == 0)
560Sstevel@tonic-gate return (rcode);
570Sstevel@tonic-gate else
580Sstevel@tonic-gate return (count);
590Sstevel@tonic-gate }
600Sstevel@tonic-gate }
610Sstevel@tonic-gate
620Sstevel@tonic-gate #else /*_CRAY*/
630Sstevel@tonic-gate
640Sstevel@tonic-gate int
__writev(fd,vp,vpcount)650Sstevel@tonic-gate __writev(fd, vp, vpcount)
660Sstevel@tonic-gate int fd;
670Sstevel@tonic-gate const struct iovec *vp;
680Sstevel@tonic-gate int vpcount;
690Sstevel@tonic-gate {
700Sstevel@tonic-gate int count = 0;
710Sstevel@tonic-gate
720Sstevel@tonic-gate while (vpcount-- > 0) {
730Sstevel@tonic-gate int written = write(fd, vp->iov_base, vp->iov_len);
740Sstevel@tonic-gate
750Sstevel@tonic-gate if (written < 0)
760Sstevel@tonic-gate return (-1);
770Sstevel@tonic-gate count += written;
780Sstevel@tonic-gate if (written != vp->iov_len)
790Sstevel@tonic-gate break;
800Sstevel@tonic-gate vp++;
810Sstevel@tonic-gate }
820Sstevel@tonic-gate return (count);
830Sstevel@tonic-gate }
840Sstevel@tonic-gate
850Sstevel@tonic-gate #endif /*_CRAY*/
860Sstevel@tonic-gate
870Sstevel@tonic-gate #endif /*NEED_WRITEV*/
88*11038SRao.Shoaib@Sun.COM
89*11038SRao.Shoaib@Sun.COM /*! \file */
90