Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!yale!cmcl2!stealth.acf.nyu.edu!brnstnd From: brnstnd@stealth.acf.nyu.edu Newsgroups: comp.unix.wizards Subject: The 4.3 BSD awrite() solution Message-ID: <1055.18:35:28@stealth.acf.nyu.edu> Date: 8 Feb 90 00:35:29 GMT Reply-To: brnstnd@stealth.acf.nyu.edu (Dan Bernstein) Distribution: usa Organization: IR Lines: 40 According to the 4.3 BSD siginterrupt() documentation, after a program executes siginterrupt(SIGALRM,1), interrupted I/O calls will return the number of bytes actually read. Then the (untested) code below should provide a true awrite(). Any comments? ---Dan #include #include extern int errno; nothing() { } int awrite(fd,buf,num) int fd; char *buf; int num; { struct itimerval it1; struct itimerval it2; struct itimerval it3; int w; int saveerrno; int (*fun)(); it1.it_interval.tv_sec = it1.it_value.tv_sec = 0; it1.it_interval.tv_usec = it1.it_value.tv_usec = 0; (void) setitimer(ITIMER_REAL,&it1,&it2); fun = signal(SIGALRM,nothing); it1.it_interval.tv_sec = it1.it_value.tv_sec = 0; it1.it_interval.tv_usec = it1.it_value.tv_usec = 10000; (void) setitimer(ITIMER_REAL,&it1,&it3); w = write(fd,buf,num); saveerrno = errno; (void) setitimer(ITIMER_REAL,&it3,&it1); (void) signal(SIGALRM,fun); (void) setitimer(ITIMER_REAL,&it2,&it3); errno = saveerrno; return(w); }