The 4.3 BSD awrite() solution

brnstnd at stealth.acf.nyu.edu brnstnd at stealth.acf.nyu.edu
Thu Feb 8 11:35:29 AEST 1990


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 <sys/time.h>
#include <signal.h>
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);
}



More information about the Comp.unix.wizards mailing list