1 #include "syshdrs.h" 2 3 #if !defined(NO_SIGNALS) && defined(SIGPIPE) 4 extern volatile Sjmp_buf gPipeJmp; 5 #endif 6 int 7 PWrite(int sfd, const char *const buf0, size_t size) 8 { 9 volatile int nleft; 10 const char *volatile buf = buf0; 11 int nwrote; 12 #if !defined(NO_SIGNALS) && defined(SIGPIPE) 13 vsio_sigproc_t sigpipe; 14 15 if (SSetjmp(gPipeJmp) != 0) { 16 (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe); 17 nwrote = size - nleft; 18 if (nwrote > 0) 19 return (nwrote); 20 errno = EPIPE; 21 return (kBrokenPipeErr); 22 } 23 24 sigpipe = (vsio_sigproc_t) SSignal(SIGPIPE, SIOHandler); 25 #endif 26 27 nleft = (int) size; 28 forever { 29 nwrote = write(sfd, buf, nleft); 30 if (nwrote < 0) { 31 if (errno != EINTR) { 32 nwrote = size - nleft; 33 if (nwrote == 0) 34 nwrote = -1; 35 goto done; 36 } else { 37 errno = 0; 38 nwrote = 0; 39 /* Try again. */ 40 } 41 } 42 nleft -= nwrote; 43 if (nleft <= 0) 44 break; 45 buf += nwrote; 46 } 47 nwrote = size - nleft; 48 49 done: 50 #if !defined(NO_SIGNALS) && defined(SIGPIPE) 51 (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe); 52 #endif 53 54 return (nwrote); 55 } /* PWrite */ 56