File: usleep.c

package info (click to toggle)
rat 4.2.22-2.2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,896 kB
  • ctags: 3,717
  • sloc: ansic: 36,542; tcl: 2,740; sh: 2,675; makefile: 295
file content (48 lines) | stat: -rw-r--r-- 1,078 bytes parent folder | download | duplicates (5)
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
/*
 * FILE:    usleep.c
 * PROGRAM: RAT
 * AUTHORS: Colin Perkins 
 *
 * Some platforms, notably Win32 and Irix 5.3 don't have a usleep
 * system call. This file provides a workaround.
 *
 * Copyright (c) 1999-2001 University College London
 * All rights reserved.
 */
 
#ifndef HIDE_SOURCE_STRINGS
static const char cvsid[] = 
	"$Id: usleep.c,v 1.6 2001/01/08 20:30:13 ucaccsp Exp $";
#endif /* HIDE_SOURCE_STRINGS */

#include "config_unix.h"
#include "config_win32.h"

#ifdef WIN32
int usleep(unsigned int usec)
{
        DWORD dur = usec/1000;
        if (dur != 0) {
		Sleep(dur);
	}
        return 0;
}
#endif

/* On Irix 6.5.4m this function isn't needed.... we should probably have */
/* a check in the configure script for usleep().                         */
#ifdef NEED_USLEEP
int usleep(unsigned int usec)
{
	struct timespec sleeptime,t2;

	sleeptime.tv_sec  = usec/1000000;
	sleeptime.tv_nsec = (usec%1000000)*1000;

	while(nanosleep(&sleeptime,&t2)){ /* if interrupted, sleep again*/
		sleeptime.tv_sec  = t2.tv_sec;
		sleeptime.tv_nsec = t2.tv_nsec;
	}
}
#endif