File: usleep.c

package info (click to toggle)
xbat 1.11-11
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,268 kB
  • ctags: 765
  • sloc: ansic: 6,287; makefile: 563; sh: 59
file content (46 lines) | stat: -rw-r--r-- 927 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef __FreeBSD__
#include <unistd.h>
#endif /* FreeBSD */

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <sys/param.h>
#include <sys/types.h>

int u_sleep(unsigned long int microSeconds)
{
      unsigned int Seconds , uSec;
      int nfds=0;
      struct timeval Timer;

      if(microSeconds == (unsigned long) 0)
	return 0;

      if( (microSeconds < (unsigned long) 0) 
	 || microSeconds > (unsigned long) 4000000)
	{
	      errno = ERANGE;
	      perror("u_sleep time out of range(0 -> 4000000)");
	      return -1;
	}
      
      Seconds = microSeconds/(unsigned long) 1000000;
      
      uSec = microSeconds %(unsigned long) 1000000;
      
      Timer.tv_sec = Seconds;
      Timer.tv_usec = uSec;
      
      if(select(nfds , NULL, NULL, NULL,&Timer) < 0)
	{
	      perror("u_sleep (select) failed ");
	      return -1;
	}
      return 0;
}