http://se.aminet.net/pub/X11/ftp.x.org/contrib/vms/xscreensaver-124.zip
[xscreensaver] / utils / usleep.c
1 /* xscreensaver, Copyright (c) 1992 Jamie Zawinski <jwz@mcom.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 #include <X11/Xlib.h>
17 #include <X11/Xos.h>    /* lazy way out */
18
19 #ifdef VMS
20 #include <descrip.h>
21 #include <stdio.h>
22 extern char *progname;
23 #include <lib$routines.h>
24 unsigned long int statvms;
25 float seconds;
26 #endif
27
28 /* usleep() doesn't exist everywhere, and select() is faster anyway.
29  */
30
31 #ifndef VMS
32
33 #ifdef NO_SELECT
34   /* If you don't have select() or usleep(), I guess you lose...
35      Maybe you have napms() instead?  Let me know.
36    */
37 void
38 screenhack_usleep (usecs)
39      unsigned long usecs;
40 {
41   usleep (usecs);
42 }
43
44 #else /* ! NO_SELECT */
45
46 void
47 screenhack_usleep (usecs)
48      unsigned long usecs;
49 {
50   struct timeval tv;
51   tv.tv_sec  = usecs / 1000000L;
52   tv.tv_usec = usecs % 1000000L;
53   (void) select (0, 0, 0, 0, &tv);
54 }
55
56 #endif /* ! NO_SELECT */
57
58 #else /* VMS */
59
60 #define SEC_DELTA  "0000 00:00:01.00"
61 #define TICK_DELTA "0000 00:00:00.08"
62 static int bin_sec_delta[2], bin_tick_delta[2], deltas_set = 0;
63
64 static void
65 set_deltas ()
66 {
67   int status;
68   extern int SYS$BINTIM ();
69   $DESCRIPTOR (str_sec_delta,  SEC_DELTA);
70   $DESCRIPTOR (str_tick_delta, TICK_DELTA);
71   if (!deltas_set)
72     {
73       status = SYS$BINTIM (&str_sec_delta, &bin_sec_delta);
74       if (!(status & 1))
75         {
76           fprintf (stderr, "%s: cannot convert delta time ", progname);
77           fprintf (stderr, SEC_DELTA);
78           fprintf (stderr, "; status code = %d\n", status);
79           exit (status);
80         }
81       status = SYS$BINTIM (&str_tick_delta, &bin_tick_delta);
82       if (!(status & 1))
83         {
84           fprintf (stderr, "%s: cannot convert delta time ", progname);
85           fprintf (stderr, TICK_DELTA);
86           fprintf (stderr, "; status code = %d\n", status);
87           exit (status);
88         }
89       deltas_set = 1;
90     }
91 }
92
93 void
94 screenhack_usleep (usecs)
95      unsigned long usecs;
96 {
97   int status, *bin_delta;
98
99 /*  extern int SYS$SCHWDK (), SYS$HIBER ();                               */
100 /*#define TICK_INTERVAL 1000                                              */
101 /*                                                                        */
102 /*  if (!deltas_set) set_deltas ();                                       */
103 /*  bin_delta = (usecs == TICK_INTERVAL) ? &bin_tick_delta : &bin_sec_delta; */
104 /*  status = SYS$SCHDWK (0, 0, bin_delta, 0);                             */
105 /*  if ((status & 1)) (void) SYS$HIBER ();                                */
106
107       seconds = ((float) usecs)/1000000.0;
108       statvms = lib$wait(&seconds);
109 }
110
111 #endif /*VMS */