make the gettimeofday() implementation in Time::HiRes available
[p5sagit/p5-mst-13.2.git] / ext / Time / HiRes / HiRes.xs
1 #ifdef __cplusplus
2 extern "C" {
3 #endif
4 #include "EXTERN.h"
5 #include "perl.h"
6 #include "XSUB.h"
7 #ifdef WIN32
8 #include <time.h>
9 #else
10 #include <sys/time.h>
11 #endif
12 #ifdef HAS_SELECT
13 # ifdef I_SYS_SELECT
14 #  include <sys/select.h>
15 # endif
16 #endif
17 #ifdef __cplusplus
18 }
19 #endif
20
21 static IV
22 constant(char *name, int arg)
23 {
24     errno = 0;
25     switch (*name) {
26     case 'I':
27       if (strEQ(name, "ITIMER_REAL"))
28 #ifdef ITIMER_REAL
29         return ITIMER_REAL;
30 #else
31         goto not_there;
32 #endif
33       if (strEQ(name, "ITIMER_REALPROF"))
34 #ifdef ITIMER_REALPROF
35         return ITIMER_REALPROF;
36 #else
37         goto not_there;
38 #endif
39       if (strEQ(name, "ITIMER_VIRTUAL"))
40 #ifdef ITIMER_VIRTUAL
41         return ITIMER_VIRTUAL;
42 #else
43         goto not_there;
44 #endif
45       if (strEQ(name, "ITIMER_PROF"))
46 #ifdef ITIMER_PROF
47         return ITIMER_PROF;
48 #else
49         goto not_there;
50 #endif
51       break;
52     }
53     errno = EINVAL;
54     return 0;
55
56 not_there:
57     errno = ENOENT;
58     return 0;
59 }
60
61 #if !defined(HAS_GETTIMEOFDAY) && defined(VMS)
62 #define HAS_GETTIMEOFDAY
63
64 #include <lnmdef.h>
65 #include <time.h> /* gettimeofday */
66 #include <stdlib.h> /* qdiv */
67 #include <starlet.h> /* sys$gettim */
68 #include <descrip.h>
69 #ifdef __VAX
70 #include <lib$routines.h> /* lib$ediv() */
71 #endif
72
73 /*
74         VMS binary time is expressed in 100 nano-seconds since
75         system base time which is 17-NOV-1858 00:00:00.00
76 */
77
78 #define DIV_100NS_TO_SECS  10000000L
79 #define DIV_100NS_TO_USECS 10L
80
81 /* 
82         gettimeofday is supposed to return times since the epoch
83         so need to determine this in terms of VMS base time
84 */
85 static $DESCRIPTOR(dscepoch,"01-JAN-1970 00:00:00.00");
86
87 #ifdef __VAX
88 static long base_adjust[2]={0L,0L};
89 #else
90 static __int64 base_adjust=0;
91 #endif
92
93 /* 
94
95    If we don't have gettimeofday, then likely we are on a VMS machine that
96    operates on local time rather than UTC...so we have to zone-adjust.
97    This code gleefully swiped from VMS.C 
98
99 */
100 /* method used to handle UTC conversions:
101  *   1 == CRTL gmtime();  2 == SYS$TIMEZONE_DIFFERENTIAL;  3 == no correction
102  */
103 static int gmtime_emulation_type;
104 /* number of secs to add to UTC POSIX-style time to get local time */
105 static long int utc_offset_secs;
106 static struct dsc$descriptor_s fildevdsc = 
107   { 12, DSC$K_DTYPE_T, DSC$K_CLASS_S, "LNM$FILE_DEV" };
108 static struct dsc$descriptor_s *fildev[] = { &fildevdsc, NULL };
109
110 static time_t toutc_dst(time_t loc) {
111   struct tm *rsltmp;
112
113   if ((rsltmp = localtime(&loc)) == NULL) return -1;
114   loc -= utc_offset_secs;
115   if (rsltmp->tm_isdst) loc -= 3600;
116   return loc;
117 }
118
119 static time_t toloc_dst(time_t utc) {
120   struct tm *rsltmp;
121
122   utc += utc_offset_secs;
123   if ((rsltmp = localtime(&utc)) == NULL) return -1;
124   if (rsltmp->tm_isdst) utc += 3600;
125   return utc;
126 }
127
128 #define _toutc(secs)  ((secs) == (time_t) -1 ? (time_t) -1 : \
129        ((gmtime_emulation_type || timezone_setup()), \
130        (gmtime_emulation_type == 1 ? toutc_dst(secs) : \
131        ((secs) - utc_offset_secs))))
132
133 #define _toloc(secs)  ((secs) == (time_t) -1 ? (time_t) -1 : \
134        ((gmtime_emulation_type || timezone_setup()), \
135        (gmtime_emulation_type == 1 ? toloc_dst(secs) : \
136        ((secs) + utc_offset_secs))))
137
138 static int
139 timezone_setup(void) 
140 {
141   struct tm *tm_p;
142
143   if (gmtime_emulation_type == 0) {
144     int dstnow;
145     time_t base = 15 * 86400; /* 15jan71; to avoid month/year ends between    */
146                               /* results of calls to gmtime() and localtime() */
147                               /* for same &base */
148
149     gmtime_emulation_type++;
150     if ((tm_p = gmtime(&base)) == NULL) { /* CRTL gmtime() is a fake */
151       char off[LNM$C_NAMLENGTH+1];;
152
153       gmtime_emulation_type++;
154       if (!Perl_vmstrnenv("SYS$TIMEZONE_DIFFERENTIAL",off,0,fildev,0)) {
155         gmtime_emulation_type++;
156         utc_offset_secs = 0;
157         Perl_warn(aTHX_ "no UTC offset information; assuming local time is UTC");
158       }
159       else { utc_offset_secs = atol(off); }
160     }
161     else { /* We've got a working gmtime() */
162       struct tm gmt, local;
163
164       gmt = *tm_p;
165       tm_p = localtime(&base);
166       local = *tm_p;
167       utc_offset_secs  = (local.tm_mday - gmt.tm_mday) * 86400;
168       utc_offset_secs += (local.tm_hour - gmt.tm_hour) * 3600;
169       utc_offset_secs += (local.tm_min  - gmt.tm_min)  * 60;
170       utc_offset_secs += (local.tm_sec  - gmt.tm_sec);
171     }
172   }
173   return 1;
174 }
175
176
177 int
178 gettimeofday (struct timeval *tp, void *tpz)
179 {
180  long ret;
181 #ifdef __VAX
182  long quad[2];
183  long quad1[2];
184  long div_100ns_to_secs;
185  long div_100ns_to_usecs;
186  long quo,rem;
187  long quo1,rem1;
188 #else
189  __int64 quad;
190  __qdiv_t ans1,ans2;
191 #endif
192 /*
193         In case of error, tv_usec = 0 and tv_sec = VMS condition code.
194         The return from function is also set to -1.
195         This is not exactly as per the manual page.
196 */
197
198  tp->tv_usec = 0;
199
200 #ifdef __VAX
201  if (base_adjust[0]==0 && base_adjust[1]==0) {
202 #else
203  if (base_adjust==0) { /* Need to determine epoch adjustment */
204 #endif
205         ret=sys$bintim(&dscepoch,&base_adjust);
206         if (1 != (ret &&1)) {
207                 tp->tv_sec = ret;
208                 return -1;
209         }
210  }
211
212  ret=sys$gettim(&quad); /* Get VMS system time */
213  if ((1 && ret) == 1) {
214 #ifdef __VAX
215         quad[0] -= base_adjust[0]; /* convert to epoch offset */
216         quad[1] -= base_adjust[1]; /* convert 2nd half of quadword */
217         div_100ns_to_secs = DIV_100NS_TO_SECS;
218         div_100ns_to_usecs = DIV_100NS_TO_USECS;
219         lib$ediv(&div_100ns_to_secs,&quad,&quo,&rem);
220         quad1[0] = rem;
221         quad1[1] = 0L;
222         lib$ediv(&div_100ns_to_usecs,&quad1,&quo1,&rem1);
223         tp->tv_sec = quo; /* Whole seconds */
224         tp->tv_usec = quo1; /* Micro-seconds */
225 #else
226         quad -= base_adjust; /* convert to epoch offset */
227         ans1=qdiv(quad,DIV_100NS_TO_SECS);
228         ans2=qdiv(ans1.rem,DIV_100NS_TO_USECS);
229         tp->tv_sec = ans1.quot; /* Whole seconds */
230         tp->tv_usec = ans2.quot; /* Micro-seconds */
231 #endif
232  } else {
233         tp->tv_sec = ret;
234         return -1;
235  }
236 # ifdef VMSISH_TIME
237 # ifdef RTL_USES_UTC
238   if (VMSISH_TIME) tp->tv_sec = _toloc(tp->tv_sec);
239 # else
240   if (!VMSISH_TIME) tp->tv_sec = _toutc(tp->tv_sec);
241 # endif
242 # endif
243  return 0;
244 }
245 #endif
246
247 #if !defined(HAS_USLEEP) && defined(HAS_SELECT)
248 #ifndef SELECT_IS_BROKEN
249 #define HAS_USLEEP
250 #define usleep hrt_usleep  /* could conflict with ncurses for static build */
251
252 void
253 hrt_usleep(unsigned long usec)
254 {
255     struct timeval tv;
256     tv.tv_sec = 0;
257     tv.tv_usec = usec;
258     select(0, (Select_fd_set_t)NULL, (Select_fd_set_t)NULL,
259                 (Select_fd_set_t)NULL, &tv);
260 }
261 #endif
262 #endif
263
264 #if !defined(HAS_USLEEP) && defined(WIN32)
265 #define HAS_USLEEP
266 #define usleep hrt_usleep  /* could conflict with ncurses for static build */
267
268 void
269 hrt_usleep(unsigned long usec)
270 {
271     long msec;
272     msec = usec / 1000;
273     Sleep (msec);
274 }
275 #endif
276
277
278 #if !defined(HAS_UALARM) && defined(HAS_SETITIMER)
279 #define HAS_UALARM
280 #define ualarm hrt_ualarm  /* could conflict with ncurses for static build */
281
282 int
283 hrt_ualarm(int usec, int interval)
284 {
285    struct itimerval itv;
286    itv.it_value.tv_sec = usec / 1000000;
287    itv.it_value.tv_usec = usec % 1000000;
288    itv.it_interval.tv_sec = interval / 1000000;
289    itv.it_interval.tv_usec = interval % 1000000;
290    return setitimer(ITIMER_REAL, &itv, 0);
291 }
292 #endif
293
294 #if !defined(HAS_UALARM) && defined(VMS)
295 #define HAS_UALARM
296 #define ualarm vms_ualarm 
297
298 #include <lib$routines.h>
299 #include <ssdef.h>
300 #include <starlet.h>
301 #include <descrip.h>
302 #include <signal.h>
303 #include <jpidef.h>
304 #include <psldef.h>
305
306 #define VMSERR(s)   (!((s)&1))
307
308 static void
309 us_to_VMS(useconds_t mseconds, unsigned long v[])
310 {
311     int iss;
312     unsigned long qq[2];
313
314     qq[0] = mseconds;
315     qq[1] = 0;
316     v[0] = v[1] = 0;
317
318     iss = lib$addx(qq,qq,qq);
319     if (VMSERR(iss)) lib$signal(iss);
320     iss = lib$subx(v,qq,v);
321     if (VMSERR(iss)) lib$signal(iss);
322     iss = lib$addx(qq,qq,qq);
323     if (VMSERR(iss)) lib$signal(iss);
324     iss = lib$subx(v,qq,v);
325     if (VMSERR(iss)) lib$signal(iss);
326     iss = lib$subx(v,qq,v);
327     if (VMSERR(iss)) lib$signal(iss);
328 }
329
330 static int
331 VMS_to_us(unsigned long v[])
332 {
333     int iss;
334     unsigned long div=10,quot, rem;
335
336     iss = lib$ediv(&div,v,&quot,&rem);
337     if (VMSERR(iss)) lib$signal(iss);
338
339     return quot;
340 }
341
342 typedef unsigned short word;
343 typedef struct _ualarm {
344     int function;
345     int repeat;
346     unsigned long delay[2];
347     unsigned long interval[2];
348     unsigned long remain[2];
349 } Alarm;
350
351
352 static int alarm_ef;
353 static Alarm *a0, alarm_base;
354 #define UAL_NULL   0
355 #define UAL_SET    1
356 #define UAL_CLEAR  2
357 #define UAL_ACTIVE 4
358 static void ualarm_AST(Alarm *a);
359
360 static int 
361 vms_ualarm(int mseconds, int interval)
362 {
363     Alarm *a, abase;
364     struct item_list3 {
365         word length;
366         word code;
367         void *bufaddr;
368         void *retlenaddr;
369     } ;
370     static struct item_list3 itmlst[2];
371     static int first = 1;
372     unsigned long asten;
373     int iss, enabled;
374
375     if (first) {
376         first = 0;
377         itmlst[0].code       = JPI$_ASTEN;
378         itmlst[0].length     = sizeof(asten);
379         itmlst[0].retlenaddr = NULL;
380         itmlst[1].code       = 0;
381         itmlst[1].length     = 0;
382         itmlst[1].bufaddr    = NULL;
383         itmlst[1].retlenaddr = NULL;
384
385         iss = lib$get_ef(&alarm_ef);
386         if (VMSERR(iss)) lib$signal(iss);
387
388         a0 = &alarm_base;
389         a0->function = UAL_NULL;
390     }
391     itmlst[0].bufaddr    = &asten;
392     
393     iss = sys$getjpiw(0,0,0,itmlst,0,0,0);
394     if (VMSERR(iss)) lib$signal(iss);
395     if (!(asten&0x08)) return -1;
396
397     a = &abase;
398     if (mseconds) {
399         a->function = UAL_SET;
400     } else {
401         a->function = UAL_CLEAR;
402     }
403
404     us_to_VMS(mseconds, a->delay);
405     if (interval) {
406         us_to_VMS(interval, a->interval);
407         a->repeat = 1;
408     } else 
409         a->repeat = 0;
410
411     iss = sys$clref(alarm_ef);
412     if (VMSERR(iss)) lib$signal(iss);
413
414     iss = sys$dclast(ualarm_AST,a,0);
415     if (VMSERR(iss)) lib$signal(iss);
416
417     iss = sys$waitfr(alarm_ef);
418     if (VMSERR(iss)) lib$signal(iss);
419
420     if (a->function == UAL_ACTIVE) 
421         return VMS_to_us(a->remain);
422     else
423         return 0;
424 }
425
426
427
428 static void
429 ualarm_AST(Alarm *a)
430 {
431     int iss;
432     unsigned long now[2];
433
434     iss = sys$gettim(now);
435     if (VMSERR(iss)) lib$signal(iss);
436
437     if (a->function == UAL_SET || a->function == UAL_CLEAR) {
438         if (a0->function == UAL_ACTIVE) {
439             iss = sys$cantim(a0,PSL$C_USER);
440             if (VMSERR(iss)) lib$signal(iss);
441
442             iss = lib$subx(a0->remain, now, a->remain);
443             if (VMSERR(iss)) lib$signal(iss);
444
445             if (a->remain[1] & 0x80000000) 
446                 a->remain[0] = a->remain[1] = 0;
447         }
448
449         if (a->function == UAL_SET) {
450             a->function = a0->function;
451             a0->function = UAL_ACTIVE;
452             a0->repeat = a->repeat;
453             if (a0->repeat) {
454                 a0->interval[0] = a->interval[0];
455                 a0->interval[1] = a->interval[1];
456             }
457             a0->delay[0] = a->delay[0];
458             a0->delay[1] = a->delay[1];
459
460             iss = lib$subx(now, a0->delay, a0->remain);
461             if (VMSERR(iss)) lib$signal(iss);
462
463             iss = sys$setimr(0,a0->delay,ualarm_AST,a0);
464             if (VMSERR(iss)) lib$signal(iss);
465         } else {
466             a->function = a0->function;
467             a0->function = UAL_NULL;
468         }
469         iss = sys$setef(alarm_ef);
470         if (VMSERR(iss)) lib$signal(iss);
471     } else if (a->function == UAL_ACTIVE) {
472         if (a->repeat) {
473             iss = lib$subx(now, a->interval, a->remain);
474             if (VMSERR(iss)) lib$signal(iss);
475
476             iss = sys$setimr(0,a->interval,ualarm_AST,a);
477             if (VMSERR(iss)) lib$signal(iss);
478         } else {
479             a->function = UAL_NULL;
480         }
481         iss = sys$wake(0,0);
482         if (VMSERR(iss)) lib$signal(iss);
483         lib$signal(SS$_ASTFLT);
484     } else {
485         lib$signal(SS$_BADPARAM);
486     }
487 }
488
489 #endif /* !HAS_UALARM && VMS */
490
491
492
493 #ifdef HAS_GETTIMEOFDAY
494
495 static int
496 myU2time(UV *ret)
497 {
498   struct timeval Tp;
499   int status;
500   status = PerlProc_gettimeofday(&Tp,NULL);
501   ret[0] = Tp.tv_sec;
502   ret[1] = Tp.tv_usec;
503   return status;
504 }
505
506 static NV
507 myNVtime()
508 {
509   struct timeval Tp;
510   int status;
511   status = PerlProc_gettimeofday(&Tp,NULL);
512   return status == 0 ? Tp.tv_sec + (Tp.tv_usec / 1000000.) : -1.0;
513 }
514
515 #endif
516
517 MODULE = Time::HiRes            PACKAGE = Time::HiRes
518
519 PROTOTYPES: ENABLE
520
521 BOOT:
522 #ifdef HAS_GETTIMEOFDAY
523 {
524   UV auv[2];
525   hv_store(PL_modglobal, "Time::NVtime", 12, newSViv(PTR2IV(myNVtime)), 0);
526   if (myU2time(auv) == 0)
527     hv_store(PL_modglobal, "Time::U2time", 12, newSViv((IV) auv[0]), 0);
528 }
529 #endif
530
531 IV
532 constant(name, arg)
533         char *          name
534         int             arg
535
536 #if defined(HAS_USLEEP) && defined(HAS_GETTIMEOFDAY)
537
538 NV
539 usleep(useconds)
540         NV useconds
541         PREINIT:
542         struct timeval Ta, Tb;
543         CODE:
544         PerlProc_gettimeofday(&Ta,NULL);
545         if (items > 0) {
546             if (useconds > 1E6) {
547                 IV seconds = (IV) (useconds / 1E6);
548                 /* If usleep() has been implemented using setitimer()
549                  * then this contortion is unnecessary-- but usleep()
550                  * may be implemented in some other way, so let's contort. */
551                 if (seconds) {
552                     sleep(seconds);
553                     useconds -= 1E6 * seconds;
554                 }
555             } else if (useconds < 0.0)
556                 croak("Time::HiRes::usleep(%"NVgf"): negative time not invented yet", useconds);
557             usleep((UV)useconds);
558         } else
559             PerlProc_pause();
560         PerlProc_gettimeofday(&Tb,NULL);
561 #if 0
562         printf("[%ld %ld] [%ld %ld]\n", Tb.tv_sec, Tb.tv_usec, Ta.tv_sec, Ta.tv_usec);
563 #endif
564         RETVAL = 1E6*(Tb.tv_sec-Ta.tv_sec)+(NV)((IV)Tb.tv_usec-(IV)Ta.tv_usec);
565
566         OUTPUT:
567         RETVAL
568
569 NV
570 sleep(...)
571         PREINIT:
572         struct timeval Ta, Tb;
573         CODE:
574         PerlProc_gettimeofday(&Ta,NULL);
575         if (items > 0) {
576             NV seconds  = SvNV(ST(0));
577             if (seconds >= 0.0) {
578                  UV useconds = (UV)(1E6 * (seconds - (UV)seconds));
579                  if (seconds >= 1.0)
580                      sleep((UV)seconds);
581                  usleep(useconds);
582             } else
583                 croak("Time::HiRes::sleep(%"NVgf"): negative time not invented yet", seconds);
584         } else
585             PerlProc_pause();
586         PerlProc_gettimeofday(&Tb,NULL);
587 #if 0
588         printf("[%ld %ld] [%ld %ld]\n", Tb.tv_sec, Tb.tv_usec, Ta.tv_sec, Ta.tv_usec);
589 #endif
590         RETVAL = (NV)(Tb.tv_sec-Ta.tv_sec)+0.000001*(NV)(Tb.tv_usec-Ta.tv_usec);
591
592         OUTPUT:
593         RETVAL
594
595 #endif
596
597 #ifdef HAS_UALARM
598
599 int
600 ualarm(useconds,interval=0)
601         int useconds
602         int interval
603         CODE:
604         if (useconds < 0 || interval < 0)
605             croak("Time::HiRes::ualarm(%d, %d): negative time not invented yet", useconds, interval);
606         RETVAL = ualarm(useconds, interval);
607
608         OUTPUT:
609         RETVAL
610
611 NV
612 alarm(seconds,interval=0)
613         NV seconds
614         NV interval
615         CODE:
616         if (seconds < 0.0 || interval < 0.0)
617             croak("Time::HiRes::alarm(%"NVgf", %"NVgf"): negative time not invented yet", seconds, interval);
618         RETVAL = (NV)ualarm(seconds  * 1000000,
619                             interval * 1000000) / 1E6;
620
621         OUTPUT:
622         RETVAL
623
624 #endif
625
626 #ifdef HAS_GETTIMEOFDAY
627 #    ifdef MACOS_TRADITIONAL    /* fix epoch TZ and use unsigned time_t */
628 void
629 gettimeofday()
630         PREINIT:
631         struct timeval Tp;
632         struct timezone Tz;
633         PPCODE:
634         int status;
635         status = PerlProc_gettimeofday(&Tp,&Tz);
636         Tp.tv_sec += Tz.tz_minuteswest * 60;    /* adjust for TZ */
637
638         if (GIMME == G_ARRAY) {
639              EXTEND(sp, 2);
640              /* Mac OS (Classic) has unsigned time_t */
641              PUSHs(sv_2mortal(newSVuv(Tp.tv_sec)));
642              PUSHs(sv_2mortal(newSViv(Tp.tv_usec)));
643         } else {
644              EXTEND(sp, 1);
645              PUSHs(sv_2mortal(newSVnv(Tp.tv_sec + (Tp.tv_usec / 1000000.0))));
646         }
647
648 NV
649 time()
650         PREINIT:
651         struct timeval Tp;
652         struct timezone Tz;
653         CODE:
654         int status;
655         status = PerlProc_gettimeofday(&Tp,&Tz);
656         Tp.tv_sec += Tz.tz_minuteswest * 60;    /* adjust for TZ */
657         RETVAL = Tp.tv_sec + (Tp.tv_usec / 1000000.0);
658         OUTPUT:
659         RETVAL
660
661 #    else       /* MACOS_TRADITIONAL */
662 void
663 gettimeofday()
664         PREINIT:
665         struct timeval Tp;
666         PPCODE:
667         int status;
668         status = PerlProc_gettimeofday(&Tp,NULL);
669         if (GIMME == G_ARRAY) {
670              EXTEND(sp, 2);
671              PUSHs(sv_2mortal(newSViv(Tp.tv_sec)));
672              PUSHs(sv_2mortal(newSViv(Tp.tv_usec)));
673         } else {
674              EXTEND(sp, 1);
675              PUSHs(sv_2mortal(newSVnv(Tp.tv_sec + (Tp.tv_usec / 1000000.0))));
676         }
677
678 NV
679 time()
680         PREINIT:
681         struct timeval Tp;
682         CODE:
683         int status;
684         status = PerlProc_gettimeofday(&Tp,NULL);
685         RETVAL = Tp.tv_sec + (Tp.tv_usec / 1000000.);
686         OUTPUT:
687         RETVAL
688
689 #    endif      /* MACOS_TRADITIONAL */
690 #endif
691
692 #if defined(HAS_GETITIMER) && defined(HAS_SETITIMER)
693
694 #define TV2NV(tv) ((NV)((tv).tv_sec) + 0.000001 * (NV)((tv).tv_usec))
695
696 void
697 setitimer(which, seconds, interval = 0)
698         int which
699         NV seconds
700         NV interval
701     PREINIT:
702         struct itimerval newit;
703         struct itimerval oldit;
704     PPCODE:
705         if (seconds < 0.0 || interval < 0.0)
706             croak("Time::HiRes::setitimer(%"IVdf", %"NVgf", %"NVgf"): negative time not invented yet", which, seconds, interval);
707         newit.it_value.tv_sec  = seconds;
708         newit.it_value.tv_usec =
709           (seconds  - (NV)newit.it_value.tv_sec)    * 1000000.0;
710         newit.it_interval.tv_sec  = interval;
711         newit.it_interval.tv_usec =
712           (interval - (NV)newit.it_interval.tv_sec) * 1000000.0;
713         if (setitimer(which, &newit, &oldit) == 0) {
714           EXTEND(sp, 1);
715           PUSHs(sv_2mortal(newSVnv(TV2NV(oldit.it_value))));
716           if (GIMME == G_ARRAY) {
717             EXTEND(sp, 1);
718             PUSHs(sv_2mortal(newSVnv(TV2NV(oldit.it_interval))));
719           }
720         }
721
722 void
723 getitimer(which)
724         int which
725     PREINIT:
726         struct itimerval nowit;
727     PPCODE:
728         if (getitimer(which, &nowit) == 0) {
729           EXTEND(sp, 1);
730           PUSHs(sv_2mortal(newSVnv(TV2NV(nowit.it_value))));
731           if (GIMME == G_ARRAY) {
732             EXTEND(sp, 1);
733             PUSHs(sv_2mortal(newSVnv(TV2NV(nowit.it_interval))));
734           }
735         }
736
737 #endif
738
739 # $Id: HiRes.xs,v 1.11 1999/03/16 02:27:38 wegscd Exp wegscd $
740
741 # $Log: HiRes.xs,v $
742 # Revision 1.11  1999/03/16 02:27:38  wegscd
743 # Add U2time, NVtime. Fix symbols for static link.
744 #
745 # Revision 1.10  1998/09/30 02:36:25  wegscd
746 # Add VMS changes.
747 #
748 # Revision 1.9  1998/07/07 02:42:06  wegscd
749 # Win32 usleep()
750 #
751 # Revision 1.8  1998/07/02 01:47:26  wegscd
752 # Add Win32 code for gettimeofday.
753 #
754 # Revision 1.7  1997/11/13 02:08:12  wegscd
755 # Add missing EXTEND in gettimeofday() scalar code.
756 #
757 # Revision 1.6  1997/11/11 02:32:35  wegscd
758 # Do something useful when calling gettimeofday() in a scalar context.
759 # The patch is courtesy of Gisle Aas.
760 #
761 # Revision 1.5  1997/11/06 03:10:47  wegscd
762 # Fake ualarm() if we have setitimer.
763 #
764 # Revision 1.4  1997/11/05 05:41:23  wegscd
765 # Turn prototypes ON (suggested by Gisle Aas)
766 #
767 # Revision 1.3  1997/10/13 20:56:15  wegscd
768 # Add PROTOTYPES: DISABLE
769 #
770 # Revision 1.2  1997/05/23 01:01:38  wegscd
771 # Conditional compilation, depending on what the OS gives us.
772 #
773 # Revision 1.1  1996/09/03 18:26:35  wegscd
774 # Initial revision
775 #
776 #