1 /* $Id: $ */
2 
3 /* Copyright (C) 1997 Sverre Hvammen Johansen,
4  * Department of Informatics, University of Oslo.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 #include "cim.h"
21 #include "config.h"
22 
23 /******************************************************************************
24                                               LONG REAL PROCEDURE CLOCKTIME  */
25 
26 #ifdef TIME_WITH_SYS_TIME
27 #include <sys/time.h>
28 #include <time.h>
29 #else
30 #ifdef HAVE_SYS_TIME_H
31 #include <sys/time.h>
32 #else
33 #include <time.h>
34 #endif
35 #endif
36 
37 #if HAVE_SYS_RESOURCE_H && HAVE_GETTIMEOFDAY
38 #include<sys/resource.h>
39 #endif
40 
41 double
__rclocktime()42 __rclocktime ()
43 {
44 #if HAVE_SYS_RESOURCE_H && HAVE_GETTIMEOFDAY
45   struct timeval tip;
46 #else
47 #if TIME_T
48   time_t clock;
49 #else
50   long clock;
51 #endif
52 #endif
53   struct tm *tmp;
54 #if HAVE_SYS_RESOURCE_H && HAVE_GETTIMEOFDAY
55   (void) gettimeofday (&tip, (struct timezone *) __NULL);
56   tmp = localtime (&tip.tv_sec);
57 #else
58 #if TIME_T
59   clock = time ((time_t *) __NULL);
60 #else
61   clock = time ((long) __NULL);
62 #endif
63   tmp = localtime (&clock);
64 #endif
65   return (((double) (tmp->tm_hour * 60 + tmp->tm_min) * 60 + tmp->tm_sec)
66 #if HAVE_SYS_RESOURCE_H && HAVE_GETTIMEOFDAY
67 	  + ((double) tip.tv_usec) / 1000000.0
68 #endif
69     );
70 }
71