began for maemo
[xscreensaver] / xscreensaver / utils / usleep.c
1 /* xscreensaver, Copyright (c) 1992, 1996, 1997, 2003
2  *  Jamie Zawinski <jwz@jwz.org>
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation.  No representations are made about the suitability of this
9  * software for any purpose.  It is provided "as is" without express or 
10  * implied warranty.
11  */
12
13 #ifdef HAVE_CONFIG_H
14 # include "config.h"
15 #else  /* !HAVE_CONFIG_H */
16 # ifndef NO_SELECT
17 #  define HAVE_SELECT
18 # endif
19 #endif /* !HAVE_CONFIG_H */
20
21 #ifdef __STDC__
22 # include <stdlib.h>
23 #endif
24
25 #ifdef HAVE_UNISTD_H
26 # include <unistd.h>
27 #endif
28
29 #if defined(VMS)
30 # include <descrip.h>
31 # include <stdio.h>
32 # include <lib$routines.h>
33 #elif defined(HAVE_SELECT)
34 # include <sys/time.h>          /* for struct timeval */
35 #endif
36
37
38 #ifdef __SCREENHACK_USLEEP_H__
39 ERROR, do not include that here
40 #endif
41
42 extern void screenhack_usleep (unsigned long usecs); /* suppress warning */
43
44 void
45 screenhack_usleep (unsigned long usecs)
46 {
47 # if defined(VMS)
48   float seconds = ((float) usecs)/1000000.0;
49   unsigned long int statvms = lib$wait(&seconds);
50
51 #elif defined(HAVE_SELECT)
52   /* usleep() doesn't exist everywhere, and select() is faster anyway. */
53   struct timeval tv;
54   tv.tv_sec  = usecs / 1000000L;
55   tv.tv_usec = usecs % 1000000L;
56   (void) select (0, 0, 0, 0, &tv);
57
58 #else /* !VMS && !HAVE_SELECT */
59   /* If you don't have select() or usleep(), I guess you lose...
60      Maybe you have napms() instead?  Let me know. */
61   usleep (usecs);
62
63 #endif /* !VMS && !HAVE_SELECT */
64 }