From 40e5a5811c6ffce9b0974e93cdd927cbcf60c157 Mon Sep 17 00:00:00 2001 From: Joe Hunkeler Date: Tue, 11 Aug 2015 16:51:37 -0400 Subject: Repatch (from linux) of OSX IRAF --- unix/os/zgtime.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 unix/os/zgtime.c (limited to 'unix/os/zgtime.c') diff --git a/unix/os/zgtime.c b/unix/os/zgtime.c new file mode 100644 index 00000000..1164b51f --- /dev/null +++ b/unix/os/zgtime.c @@ -0,0 +1,65 @@ +/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + */ + +#include +#include +#ifndef SYSV +#include +#endif +#include +#include +#include + +#define import_kernel +#define import_knames +#define import_spp +#include + +/* ZGTIME -- Get the local standard (clock) time, in units of seconds + * since 00:00:00 01-Jan-80. Return the total cpu time consumed by the + * process (and any subprocesses), in units of milliseconds. + */ +int +ZGTIME ( + XLONG *clock_time, /* seconds */ + XLONG *cpu_time /* milliseconds */ +) +{ + struct tms t; +#ifdef BSD + time_t time(); +#else + long time(); +#endif + time_t gmt_to_lst(); + long cpu, clkfreq; + + +#ifdef LINUX + clkfreq = CLOCKS_PER_SEC; +#else +#ifdef MACOSX + clkfreq = CLOCKS_PER_SEC; +#else + clkfreq = CLKFREQ; /* from */ +#endif +#endif + + times (&t); + *clock_time = gmt_to_lst ((time_t)time(0)); + + /* We don't want any floating point in the kernel code so do the + * following computation using integer arithment, taking care to + * avoid integer overflow (unless unavoidable) or loss of precision. + */ + cpu = (t.tms_utime + t.tms_cutime); + + if (cpu > MAX_LONG/1000) + /* *cpu_time = cpu / clkfreq * 1000;*/ + *cpu_time = cpu / 10; + else + /* *cpu_time = cpu * 1000 / clkfreq;*/ + *cpu_time = cpu * 10; + + return (XOK); +} -- cgit