pwr_tStatus time_Dmul ( pwr_tDeltaTime *result, pwr_tDeltaTime *t1, pwr_tInt32 fac ) { pwr_tInt64 nsec1, nsec2, sum; int sec = t1->tv_sec * fac; int mul = 1000000000; int addend = 0; int sts; sts = lib$emul(&sec, &mul, &addend, &nsec1); if (EVEN(sts)) return sts; sts = lib$emul(&t1->tv_nsec, &fac, &addend, &nsec2); if (EVEN(sts)) return sts; sts = lib$addx(&nsec1, &nsec2, &sum); if (EVEN(sts)) return sts; sts = lib$ediv(&mul, &sum, &result->tv_sec, &result->tv_nsec); if (EVEN(sts)) return sts; return TIME__SUCCESS; }
static pwr_tTime * vms_to_abs ( pwr_tStatus *status, pwr_tTime *tp, time_tOs *vt ) { time_tOs tmp; time_tOs time; time_tOs ofs = {0x4beb4000, 0x007c9567}; int divisor = 10000000; struct tm *tmpTm; unsigned long t = 0; pwr_dStatus(sts, status, TIME__SUCCESS); if (tp == NULL) tp = (pwr_tTime *) &time; *sts = lib$subx(vt, &ofs, &tmp); if (EVEN(*sts)) return NULL; *sts = lib$ediv(&divisor, &tmp, &tp->tv_sec, &tp->tv_nsec); if (EVEN(*sts)) return NULL; tp->tv_nsec *= 100; /* Get the time zone offset. */ tmpTm = localtime(&tp->tv_sec); tp->tv_sec -= tmpTm->tm_gmtoff - tmpTm->tm_isdst * 3600; return tp; }
static int VMS_to_us(unsigned long v[]) { int iss; unsigned long div=10,quot, rem; iss = lib$ediv(&div,v,",&rem); if (VMSERR(iss)) lib$signal(iss); return quot; }
static void file_cvttime( unsigned int *curtime, time_t *unixtime ) { static const size_t divisor = 10000000; static unsigned int bastim[2] = { 0x4BEB4000, 0x007C9567 }; /* 1/1/1970 */ int delta[2], remainder; lib$subx( curtime, bastim, delta ); lib$ediv( &divisor, delta, unixtime, &remainder ); }
static pwr_tDeltaTime * vms_to_delta ( pwr_tStatus *status, pwr_tDeltaTime *tp, time_tOs *vt ) { time_tOs time; int divisor = -10000000; pwr_dStatus(sts, status, TIME__SUCCESS); if (tp == NULL) tp = (pwr_tDeltaTime *)&time; *sts = lib$ediv(&divisor, vt, &tp->tv_sec, &tp->tv_nsec); if (EVEN(*sts)) return NULL; tp->tv_nsec *= 100; return tp; }
int clock_gettime ( clockid_t clockid, struct timespec *pt ) { unsigned long sts; pwr_tVaxTime vt; pwr_tVaxTime tmp; pwr_tVaxTime ofs = {0x4beb4000, 0x007c9567}; int divisor = 10000000; struct tm *tmpTm; unsigned long t = 0; if (clockid != CLOCK_REALTIME) { errno = EINVAL; return -1; } sts = sys$gettim(&vt); sts = lib$subx(&vt, &ofs, &tmp); if (EVEN(sts)) { errno = sts; return -1; } sts = lib$ediv(&divisor, &tmp, &pt->tv_sec, &pt->tv_nsec); if (EVEN(sts)) { errno = sts; return -1; } pt->tv_nsec *= 100; tmpTm = localtime(&pt->tv_sec); pt->tv_sec -= tmpTm->tm_gmtoff - tmpTm->tm_isdst * 3600; return 0; }
static pwr_tTime * nowTime ( pwr_tTime *tp ) { #if defined OS_VMS /* This code is valid up to 497 days after boot. */ void *argv[3]; pwr_tStatus sts; argv[0] = (void *) 2; argv[1] = &tp->tv_sec; argv[2] = &tp->tv_nsec; sts = sys$cmexec(&vmsUpTime, argv); tp->tv_nsec %= 100; tp->tv_nsec *= 10000000; #elif defined OS_ELN pwr_tStatus sts; int tmp[2]; int div = -10000000; ker$get_uptime(&sts, &tmp); sts = lib$ediv(&div, &tmp, &tp->tv_sec, &tp->tv_nsec); tp->tv_nsec *= -100; #elif defined OS_LYNX clock_gettime(CLOCK_REALTIME, tp); #endif return tp; }
int gettimeofday (struct timeval *tp, void *tpz) { long ret; #ifdef __VAX long quad[2]; long quad1[2]; long div_100ns_to_secs; long div_100ns_to_usecs; long quo,rem; long quo1,rem1; #else __int64 quad; __qdiv_t ans1,ans2; #endif /* In case of error, tv_usec = 0 and tv_sec = VMS condition code. The return from function is also set to -1. This is not exactly as per the manual page. */ tp->tv_usec = 0; #ifdef __VAX if (base_adjust[0]==0 && base_adjust[1]==0) { #else if (base_adjust==0) { /* Need to determine epoch adjustment */ #endif ret=sys$bintim(&dscepoch,&base_adjust); if (1 != (ret &&1)) { tp->tv_sec = ret; return -1; } } ret=sys$gettim(&quad); /* Get VMS system time */ if ((1 && ret) == 1) { #ifdef __VAX quad[0] -= base_adjust[0]; /* convert to epoch offset */ quad[1] -= base_adjust[1]; /* convert 2nd half of quadword */ div_100ns_to_secs = DIV_100NS_TO_SECS; div_100ns_to_usecs = DIV_100NS_TO_USECS; lib$ediv(&div_100ns_to_secs,&quad,&quo,&rem); quad1[0] = rem; quad1[1] = 0L; lib$ediv(&div_100ns_to_usecs,&quad1,&quo1,&rem1); tp->tv_sec = quo; /* Whole seconds */ tp->tv_usec = quo1; /* Micro-seconds */ #else quad -= base_adjust; /* convert to epoch offset */ ans1=qdiv(quad,DIV_100NS_TO_SECS); ans2=qdiv(ans1.rem,DIV_100NS_TO_USECS); tp->tv_sec = ans1.quot; /* Whole seconds */ tp->tv_usec = ans2.quot; /* Micro-seconds */ #endif } else { tp->tv_sec = ret; return -1; } # ifdef VMSISH_TIME # ifdef RTL_USES_UTC if (VMSISH_TIME) tp->tv_sec = _toloc(tp->tv_sec); # else if (!VMSISH_TIME) tp->tv_sec = _toutc(tp->tv_sec); # endif # endif return 0; } #endif /* Do not use H A S _ N A N O S L E E P * so that Perl Configure doesn't scan for it. * The TIME_HIRES_NANOSLEEP is set by Makefile.PL. */ #if !defined(HAS_USLEEP) && defined(TIME_HIRES_NANOSLEEP) #define HAS_USLEEP #define usleep hrt_unanosleep /* could conflict with ncurses for static build */ void hrt_unanosleep(unsigned long usec) /* This is used to emulate usleep. */ { struct timespec res; res.tv_sec = usec/1000/1000; res.tv_nsec = ( usec - res.tv_sec*1000*1000 ) * 1000; nanosleep(&res, NULL); } #endif /* #if !defined(HAS_USLEEP) && defined(TIME_HIRES_NANOSLEEP) */ #if !defined(HAS_USLEEP) && defined(HAS_SELECT) #ifndef SELECT_IS_BROKEN #define HAS_USLEEP #define usleep hrt_usleep /* could conflict with ncurses for static build */ void hrt_usleep(unsigned long usec) { struct timeval tv; tv.tv_sec = 0; tv.tv_usec = usec; select(0, (Select_fd_set_t)NULL, (Select_fd_set_t)NULL, (Select_fd_set_t)NULL, &tv); } #endif #endif /* #if !defined(HAS_USLEEP) && defined(HAS_SELECT) */ #if !defined(HAS_USLEEP) && defined(WIN32) #define HAS_USLEEP #define usleep hrt_usleep /* could conflict with ncurses for static build */ void hrt_usleep(unsigned long usec) { long msec; msec = usec / 1000; Sleep (msec); }
/* Wait for either Timer, Alternate Input, or an X Event to arrive */ int XETrapWaitForSomething(XtAppContext app) { #ifndef vms return(_XtWaitForSomething(app, FALSE, FALSE, FALSE, FALSE, TRUE #ifdef XTHREADS , FALSE #endif /* XTHREADS */ , 0L)); #else /* vms */ #define IS_AFTER(t1,t2) (((t2).high > (t1).high) \ ||(((t2).high == (t1).high)&& ((t2).low > (t1).low))) long retval = 0L; TimerEventRec *te_ptr; vms_time cur_time,result_time; int status = 0; long quotient, remainder = 0; int d; if (app->timerQueue!= NULL) { /* check timeout queue */ cur_time.low = cur_time.high = result_time.low = result_time.high = 0; te_ptr = app->timerQueue; sys$gettim(&cur_time); if ((IS_AFTER(app->timerQueue->te_timer_value, cur_time)) && (app->timerQueue->te_proc != 0)) { /* it's fired! return! */ return(0); } /* Jump through hoops to get the time specified in the queue into * milliseconds */ status = lib$sub_times (&(te_ptr->te_timer_value.low), &cur_time, &result_time); /* * See if this timer has expired. A timer is considered expired * if it's value in the past (the NEGTIM case) or if there is * less than one integral milli second before it would go off. */ if (status == LIB$_NEGTIM || (result_time.high == -1 && result_time.low > -10000)) { /* We've got a timer and it's ready to fire! */ return(0); } else if ((status & 1) == 1) { lib$ediv (&(10000), &result_time, "ient, &remainder); quotient *= -1; /* flip the sign bit */ return(XMultiplexInput(app->count, &(app->list[0L]), app->Input_EF_Mask, quotient, 0L, &retval)); } else { status = -1; } } return((status == -1 ? -1 : XMultiplexInput(app->count, &(app->list[0L]), app->Input_EF_Mask, 0L, 0L, &retval))); #endif /* vms */ }