Jspice3
time.c
Go to the documentation of this file.
1 /***************************************************************************
2 JSPICE3 adaptation of Spice3e2 - Copyright (c) Stephen R. Whiteley 1992
3 Copyright 1990 Regents of the University of California. All rights reserved.
4 Authors: UCB CAD Group
5  1992 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 /*
9  * Date and time utility functions
10  */
11 
12 #include "spice.h"
13 #include "misc.h"
14 
15 #ifdef HAVE_GETTIMEOFDAY
16 #include <sys/types.h>
17 #include <sys/time.h>
18 #include <time.h>
19 #include <sys/resource.h>
20 #else
21 #ifdef HAVE_TIMES
22 #include <sys/types.h>
23 #include <sys/times.h>
24 #include <sys/param.h>
25 #else
26 #ifdef HAVE_FTIME
27 /* default to ftime if we can't get real CPU times */
28 #include <sys/types.h>
29 #include <sys/timeb.h>
30 #endif
31 #endif
32 #endif
33 
34 /* Return the date. Return value is static data. */
35 
36 char *
38 
39 {
40 
41 #if defined(HAVE_GETTIMEOFDAY) || defined(HAVE_TIMES)
42  struct tm *tp;
43  static char tbuf[40];
44  char *ap;
45  int i;
46 #ifdef HAVE_GETTIMEOFDAY
47  struct timeval tv;
48  struct timezone tz;
49 
50  (void) gettimeofday(&tv, &tz);
51  tp = localtime(&tv.tv_sec);
52  ap = asctime(tp);
53 #else
54  long tloc;
55 
56  time(&tloc);
57  tp = localtime(&tloc);
58  ap = asctime(tp);
59 #endif
60 
61  strcpy(tbuf,ap);
62  i = strlen(tbuf);
63  tbuf[i - 1] = '\0';
64  return (tbuf);
65 
66 #else
67 
68  return ("today");
69 
70 #endif
71 }
72 
73 /* return time interval in seconds and milliseconds */
74 
75 #ifndef HAVE_GETTIMEOFDAY
76 #ifndef HAVE_TIMES
77 #ifdef HAVE_FTIME
78 
79 struct timeb timebegin;
80 
81 void
82 timediff(now, begin, sec, msec)
83 struct timeb *now, *begin;
84 int *sec, *msec;
85 {
86  *msec = now->millitm - begin->millitm;
87  *sec = now->time - begin->time;
88  if (*msec < 0) {
89  *msec += 1000;
90  (*sec)--;
91  }
92  return;
93 }
94 
95 #endif
96 #endif
97 #endif
98 
99 
100 /* How many seconds have elapsed in running time. */
101 
102 double
104 
105 {
106 #ifdef MSDOS
107  unsigned long tics = (unsigned long)dos_tics();
108  return ((double) tics*0.054945); /* 1/18.2 */
109 #else
110 #ifdef HAVE_GETTIMEOFDAY
111  struct timeval tv;
112  struct timezone tz;
113 
114  (void) gettimeofday(&tv, &tz);
115  return
116  (tv.tv_sec + (double) tv.tv_usec / 1000000.0);
117 #else
118 #ifdef HAVE_FTIME
119  struct timeb timenow;
120  int sec, msec;
121 
122  ftime(&timenow);
123  timediff(&timenow, &timebegin, &sec, &msec);
124  return (sec + (double) msec / 1000.0);
125 #else
126 #ifdef HAVE_VMSHACK
127  return ((double)clock()/(double)CLK_TCK);
128 #else /* unknown */
129  /* don't know how to do this in general. */
130  return (-1.0); /* Obvious error condition */
131 #endif /* !VMS */
132 #endif /* !FTIME */
133 #endif /* !BSD */
134 #endif /* DOS */
135 
136 }
char * strcpy()
char * datestring()
Definition: time.c:37
double seconds()
Definition: time.c:103