17c478bd9Sstevel@tonic-gate #include "port_before.h"
27c478bd9Sstevel@tonic-gate
37c478bd9Sstevel@tonic-gate #include <sys/types.h>
47c478bd9Sstevel@tonic-gate #include <sys/uio.h>
57c478bd9Sstevel@tonic-gate #include <sys/stat.h>
67c478bd9Sstevel@tonic-gate #include <sys/socket.h>
77c478bd9Sstevel@tonic-gate
87c478bd9Sstevel@tonic-gate #include "port_after.h"
97c478bd9Sstevel@tonic-gate
107c478bd9Sstevel@tonic-gate #ifndef NEED_WRITEV
117c478bd9Sstevel@tonic-gate int __bindcompat_writev;
127c478bd9Sstevel@tonic-gate #else
137c478bd9Sstevel@tonic-gate
147c478bd9Sstevel@tonic-gate #ifdef _CRAY
157c478bd9Sstevel@tonic-gate #define OWN_WRITEV
167c478bd9Sstevel@tonic-gate int
__writev(int fd,struct iovec * iov,int iovlen)177c478bd9Sstevel@tonic-gate __writev(int fd, struct iovec *iov, int iovlen)
187c478bd9Sstevel@tonic-gate {
197c478bd9Sstevel@tonic-gate struct stat statbuf;
207c478bd9Sstevel@tonic-gate
217c478bd9Sstevel@tonic-gate if (fstat(fd, &statbuf) < 0)
227c478bd9Sstevel@tonic-gate return (-1);
237c478bd9Sstevel@tonic-gate
247c478bd9Sstevel@tonic-gate /*
257c478bd9Sstevel@tonic-gate * Allow for atomic writes to network.
267c478bd9Sstevel@tonic-gate */
27*9525b14bSRao Shoaib if (statbuf.st_mode & S_IFSOCK) {
287c478bd9Sstevel@tonic-gate struct msghdr mesg;
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate memset(&mesg, 0, sizeof(mesg));
317c478bd9Sstevel@tonic-gate mesg.msg_name = 0;
327c478bd9Sstevel@tonic-gate mesg.msg_namelen = 0;
337c478bd9Sstevel@tonic-gate mesg.msg_iov = iov;
347c478bd9Sstevel@tonic-gate mesg.msg_iovlen = iovlen;
357c478bd9Sstevel@tonic-gate mesg.msg_accrights = 0;
367c478bd9Sstevel@tonic-gate mesg.msg_accrightslen = 0;
377c478bd9Sstevel@tonic-gate return (sendmsg(fd, &mesg, 0));
387c478bd9Sstevel@tonic-gate } else {
397c478bd9Sstevel@tonic-gate struct iovec *tv;
407c478bd9Sstevel@tonic-gate int i, rcode = 0, count = 0;
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate for (i = 0, tv = iov; i <= iovlen; tv++) {
437c478bd9Sstevel@tonic-gate rcode = write(fd, tv->iov_base, tv->iov_len);
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate if (rcode < 0)
467c478bd9Sstevel@tonic-gate break;
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate count += rcode;
497c478bd9Sstevel@tonic-gate }
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate if (count == 0)
527c478bd9Sstevel@tonic-gate return (rcode);
537c478bd9Sstevel@tonic-gate else
547c478bd9Sstevel@tonic-gate return (count);
557c478bd9Sstevel@tonic-gate }
567c478bd9Sstevel@tonic-gate }
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate #else /*_CRAY*/
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate int
__writev(fd,vp,vpcount)617c478bd9Sstevel@tonic-gate __writev(fd, vp, vpcount)
627c478bd9Sstevel@tonic-gate int fd;
637c478bd9Sstevel@tonic-gate const struct iovec *vp;
647c478bd9Sstevel@tonic-gate int vpcount;
657c478bd9Sstevel@tonic-gate {
667c478bd9Sstevel@tonic-gate int count = 0;
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate while (vpcount-- > 0) {
697c478bd9Sstevel@tonic-gate int written = write(fd, vp->iov_base, vp->iov_len);
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate if (written < 0)
727c478bd9Sstevel@tonic-gate return (-1);
737c478bd9Sstevel@tonic-gate count += written;
747c478bd9Sstevel@tonic-gate if (written != vp->iov_len)
757c478bd9Sstevel@tonic-gate break;
767c478bd9Sstevel@tonic-gate vp++;
777c478bd9Sstevel@tonic-gate }
787c478bd9Sstevel@tonic-gate return (count);
797c478bd9Sstevel@tonic-gate }
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate #endif /*_CRAY*/
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate #endif /*NEED_WRITEV*/
84*9525b14bSRao Shoaib
85*9525b14bSRao Shoaib /*! \file */
86