Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uunet!icom!xwkg.Icom.Com!andy From: andy@xwkg.Icom.Com (Andrew H. Marrinson) Newsgroups: comp.unix.wizards Subject: Re: usleep by poll() Message-ID: Date: 2 Apr 91 21:15:18 GMT References: <2171@estevax.UUCP> <126500@uunet.UU.NET> <6925@auspex.auspex.com> <999@muffin.cme.nist.gov> Sender: news@icom.icom.com (News Feed) Organization: Icom Systems, Inc. Lines: 43 libes@cme.nist.gov (Don Libes) writes: I recommend one slight fix to this usleep routine. Some versions of 5.3 have a bug where the first argument to poll is checked for a valid memory address even if the second argument is zero. Thus, the version you posted will fail with an EFAULT on systems with the bug. Changing it as follows will improve this: >/* >subseconds sleeps for System V - or anything that has poll() >Don Libes, 4/1/1991 >[...] >Returns 0 if successful timeout, -1 if unsuccessful. >*/ >#include >int >usleep(usec) >unsigned int usec; /* microseconds */ >{ > static subtotal = 0; /* microseconds */ > int msec; /* milliseconds */ struct pollfd foo; /* ADD!!! */ > subtotal += usec; > /* if less then 1 msec request, do nothing but remember it */ > if (subtotal < 1000) return(0); > msec = subtotal/1000; > subtotal = subtotal%1000; > return poll(&foo,(unsigned long)0,msec); /* CHANGE!!! */ >} Hope this helps those who couldn't get the above to work on System V/386 and perhaps others... -- Andrew H. Marrinson Icom Systems, Inc. Wheeling, IL, USA (andy@icom.icom.com)