ftp://ftp.zenez.com/pub/SCO/Skunk96/UnixWare/FreeBird/x11/utils/xscreensaver-1.18...
[xscreensaver] / utils / usleep.c
1 /* xscreensaver, Copyright (c) 1992 Jamie Zawinski <jwz@lucid.com>
2  *
3  * Permission to use, copy, modify, distribute, and sell this software and its
4  * documentation for any purpose is hereby granted without fee, provided that
5  * the above copyright notice appear in all copies and that both that
6  * copyright notice and this permission notice appear in supporting
7  * documentation.  No representations are made about the suitability of this
8  * software for any purpose.  It is provided "as is" without express or 
9  * implied warranty.
10  */
11
12 #if __STDC__
13 #include <stdlib.h>
14 #endif
15
16 #ifdef SVR4
17 #include <sys/time.h>
18 #endif
19
20 #include <X11/Xlib.h>
21 #include <X11/Xos.h>    /* lazy way out */
22
23 /* usleep() doesn't exist everywhere, and select() is faster anyway.
24  */
25
26 #ifndef VMS
27
28 #ifdef NO_SELECT
29   /* If you don't have select() or usleep(), I guess you lose...
30      Maybe you have napms() instead?  Let me know.
31    */
32 void
33 screenhack_usleep (usecs)
34      unsigned long usecs;
35 {
36   usleep (usecs);
37 }
38
39 #else /* ! NO_SELECT */
40
41 void
42 screenhack_usleep (usecs)
43      unsigned long usecs;
44 {
45   struct timeval tv;
46   tv.tv_sec  = usecs / 1000000L;
47   tv.tv_usec = usecs % 1000000L;
48   (void) select (0, 0, 0, 0, &tv);
49 }
50
51 #endif /* ! NO_SELECT */
52
53 #else /* VMS */
54
55 #define SEC_DELTA  "0000 00:00:01.00"
56 #define TICK_DELTA "0000 00:00:00.08"
57 static int bin_sec_delta[2], bin_tick_delta[2], deltas_set = 0;
58
59 static void
60 set_deltas ()
61 {
62   int status;
63   extern int SYS$BINTIM ();
64   $DESCRIPTOR (str_sec_delta,  SEC_DELTA);
65   $DESCRIPTOR (str_tick_delta, TICK_DELTA);
66   if (!deltas_set)
67     {
68       status = SYS$BINTIM (&str_sec_delta, &bin_sec_delta);
69       if (!(status & 1))
70         {
71           fprintf (stderr, "%s: cannot convert delta time ", progname);
72           fprintf (stderr, SEC_DELTA);
73           fprintf (stderr, "; status code = %d\n", status);
74           exit (status);
75         }
76       status = SYS$BINTIM (&str_tick_delta, &bin_tick_delta);
77       if (!(status & 1))
78         {
79           fprintf (stderr, "%s: cannot convert delta time ", progname);
80           fprintf (stderr, TICK_DELTA);
81           fprintf (stderr, "; status code = %d\n", status);
82           exit (status);
83         }
84       deltas_set = 1;
85     }
86 }
87
88 void
89 screenhack_usleep (usecs)
90      unsigned long usecs;
91 {
92   int status, *bin_delta;
93   extern int SYS$SCHWDK (), SYS$HIBER (); 
94   
95   if (!deltas_set) set_deltas ();
96   bin_delta = (usecs == TICK_INTERVAL) ? &bin_tick_delta : &bin_sec_delta;
97   status = SYS$SCHDWK (0, 0, bin_delta, 0);
98   if ((status & 1)) (void) SYS$HIBER ();
99 }
100
101 #endif /*VMS */