1 #if !defined(lint) && !defined(DOS)
2 static char rcsid
[] = "$Id: debugtime.c 770 2007-10-24 00:23:09Z hubert@u.washington.edu $";
6 * ========================================================================
7 * Copyright 2013-2021 Eduardo Chappa
8 * Copyright 2006 University of Washington
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
22 #include "debugtime.h"
27 * Returns a pointer to static string for a timestamp.
29 * If timestamp is set .subseconds are added if available.
30 * If include_date is set the date is appended.
33 debug_time(int include_date
, int include_subseconds
, int signal_in_progress
)
41 struct _timeb timebuffer
;
43 static char timestring
[23];
47 if(signal_in_progress
)
48 return _("Time Unavailable");
53 if(gettimeofday(&tp
, &tzp
) == 0){
54 t
= (time_t)tp
.tv_sec
;
56 tm_now
= localtime(&t
);
57 snprintf(datestr
, sizeof(datestr
), " %d/%d", tm_now
->tm_mon
+1, tm_now
->tm_mday
);
62 if(include_subseconds
)
63 snprintf(subsecond
, sizeof(subsecond
), ".%06ld", tp
.tv_usec
);
67 snprintf(timestring
, sizeof(timestring
), "%.8s%.7s%.6s", ctime(&t
)+11, subsecond
, datestr
);
69 #else /* !HAVE_GETTIMEOFDAY */
70 /* Should be _WINDOWS */
71 t
= time((time_t *)0);
73 tm_now
= localtime(&t
);
74 snprintf(datestr
, sizeof(datestr
), " %d/%d", tm_now
->tm_mon
+1, tm_now
->tm_mday
);
79 if(include_subseconds
){
81 snprintf(subsecond
, sizeof(subsecond
), ".%03ld", timebuffer
.millitm
);
86 snprintf(timestring
, sizeof(timestring
), "%.8s%.7s%.6s", ctime(&t
)+11, subsecond
, datestr
);
87 #endif /* HAVE_GETTIMEOFDAY */
95 * Fills in the passed in structure with the current time.
101 get_time(TIMEVAL_S
*our_time_val
)
103 #if HAVE_GETTIMEOFDAY
107 if(gettimeofday(&tp
, &tzp
) == 0){
108 our_time_val
->sec
= tp
.tv_sec
;
109 our_time_val
->usec
= tp
.tv_usec
;
112 #else /* !HAVE_GETTIMEOFDAY */
114 struct _timeb timebuffer
;
117 our_time_val
->sec
= (long)timebuffer
.time
;
118 our_time_val
->usec
= 1000L * (long)timebuffer
.millitm
;
128 * Returns the difference between the two values, in microseconds.
129 * Value returned is first - second.
132 time_diff(TIMEVAL_S
*first
, TIMEVAL_S
*second
)
134 return(1000000L*(first
->sec
- second
->sec
) + (first
->usec
- second
->usec
));