-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaksltime.c
85 lines (78 loc) · 2.42 KB
/
aksltime.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// src/aksl/aksltime.c 2017-10-25 Alan U. Kennington.
/*-----------------------------------------------------------------------------
Copyright (C) 1989-2018, Alan U. Kennington.
You may distribute this software under the terms of Alan U. Kennington's
modified Artistic Licence, as specified in the accompanying LICENCE file.
-----------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
Functions in this file:
gettime
ftime_diff
------------------------------------------------------------------------------*/
// AKSL header files:
#include "aksl/aksltime.h"
#ifndef AKSL_AKSLDEFS_H
#include "aksl/aksldefs.h"
#endif
#ifndef AKSL_CONFIG_H
#include "aksl/config.h"
#endif
// System header files:
#ifndef AKSL_X_ERRNO_H
#define AKSL_X_ERRNO_H
#include <errno.h>
#endif
// Linux needs this for definition of perror().
#if defined(WIN32) || defined(linux)
#ifndef AKSL_X_STDIO_H
#define AKSL_X_STDIO_H
#include <stdio.h>
#endif
#endif
#ifdef WIN32
#ifndef AKSL_X_SYS_TIMEB_H
#define AKSL_X_SYS_TIMEB_H
#include <sys/timeb.h>
#endif
#endif
//----------------------//
// gettime //
//----------------------//
int gettime(timeval& tv) {
// #if !defined(WIN32)
#ifdef HAVE_GETTIMEOFDAY
#ifdef SOLARIS
if (gettimeofday(&tv, (void*)0) < 0) {
#else /* SOLARIS */
if (gettimeofday(&tv, (struct timezone*)0) < 0) {
#endif /* SOLARIS */
// cout << "Error returned by gettimeofday()." << endl;
cout << flush;
perror("gettimeofday");
return -1;
}
#else /* HAVE_GETTIMEOFDAY */
// The win32 case.
// If anyone knows how to get usec out of win32, please let me know!
struct _timeb tb;
tb.time = 0;
_ftime(&tb);
if (tb.time == 0)
return -1;
tv.tv_sec = tb.time;
tv.tv_usec = long(tb.millitm) * 1000;
#endif /* HAVE_GETTIMEOFDAY */
return 0;
} // End of function gettime.
#if defined(sun) || defined(WIN32)
/*------------------------------------------------------------------------------
Returns the time t1 - t0, in milliseconds.
------------------------------------------------------------------------------*/
//----------------------//
// ftime_diff //
//----------------------//
int ftime_diff(const timeb& t0, const timeb& t1) {
time_t ds = t1.time - t0.time;
return ds * 1000 + t1.millitm - t0.millitm;
} // End of function ftime_diff.
#endif /* sun */