aboutsummaryrefslogtreecommitdiff
path: root/unix/os/zgtime.c
diff options
context:
space:
mode:
Diffstat (limited to 'unix/os/zgtime.c')
-rw-r--r--unix/os/zgtime.c65
1 files changed, 65 insertions, 0 deletions
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 <stdio.h>
+#include <sys/types.h>
+#ifndef SYSV
+#include <sys/timeb.h>
+#endif
+#include <sys/times.h>
+#include <sys/time.h>
+#include <time.h>
+
+#define import_kernel
+#define import_knames
+#define import_spp
+#include <iraf.h>
+
+/* 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 <kernel.h> */
+#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);
+}