File: usleep.c

package info (click to toggle)
xbat 1.11-9
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,236 kB
  • ctags: 796
  • sloc: ansic: 6,298; makefile: 654; sh: 63
file content (50 lines) | stat: -rw-r--r-- 974 bytes parent folder | download
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
47
48
49
50
#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)
{
#if 0
      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;
	}
#else
      usleep(microSeconds);
#endif
      return 0;
}