/* sleep -- sleep for a specified number of seconds */
/* usleep -- sleep for a specified number of microSecond */
/* written by Eric R. Smith and placed in the public domain */

#include <time.h>
#include <unistd.h>

/* clock() has a rez of CLOCKS_PER_SEC ticks/sec */

#define USEC_PER_TICK (1000000L / ((unsigned long)CLOCKS_PER_SEC))
#define	USEC_TO_CLOCK_TICKS(us)	((us) / USEC_PER_TICK )

unsigned int
sleep(n)
	unsigned int n;
{
	unsigned long	stop;

	stop = clock() + n * CLOCKS_PER_SEC;
	while (clock() < stop)
		;

	return 0;
}

/*
 * Sleep for usec microSeconds 
 * the actual suspension time can be arbitrarily longer
 *
 */
void
usleep(usec)
unsigned long usec;
{
	unsigned long	stop;

	stop = clock() + USEC_TO_CLOCK_TICKS(usec);
	while (clock() < stop)
		;
}
