looking for usleep() implementation for ULTRIX

Alexios Zavras zvr at natasha.cs.wisc.EDU
Thu Oct 19 12:13:17 AEST 1989


In article <5508 at shlump.nac.dec.com>, michaud at decvax.dec.com (Jeff
Michaud) writes:
> 	To make this really generic it should be defined as a function.  As a
> 	macro things like:
> 		if( ... )
> 			usleep(...);
> 		else
> 			....
> 	because the "usleep(...);" is two statements, ie. a compound statement and
> 	the null statement.  This can be worked around if you use an explicit
> 	compound statement around the "usleep(...);" while keeping your code
> 	portable.

The way to #define a macro as two or more statements,
without having this problem is:

#define macro(x)	do { stmt1(x); stmt2(x); ... } while (0);

So, the definition of usleep() looks like:

/*=========================================================================*/

#ifdef  ultrix

#ifndef _TYPES_
#include    <sys/types.h>
#endif  /* _TYPES_ */
#ifndef __XTIME__
#include    <sys/time.h>
#endif  /* __XTIME__ */

#define usleep(usec)
        do                                                              \
        {                                                                \
            struct timeval  usl_delay;                                    \
            usl_delay.tv_sec  = (int) (usec) / 1000000;                    \
            usl_delay.tv_usec = (int) (usec) % 1000000;                     \
            (void) select(0,(fd_set *)0,(fd_set *)0,(fd_set *)0, &usl_delay);\
        } while (0);

#endif  /* ultrix */

/*=========================================================================*/


> |Jeff Michaud    michaud at decwrl.dec.com  michaud at decvax.dec.com|

-- zvr --
	+-----------------------+	Alexios Zavras
	| Life is once, forever |	zvr at cs.wisc.edu
	+-----------------H C-B-+	zavras at cs.wisc.edu
Live from:
Wisconsin: land of Orson Welles, Frank Lloyd Wright,
		   Harry Houdini  and Spencer Tracy
	       (of Joe McCarthy, too, but we try to forget that)



More information about the Comp.unix.ultrix mailing list