| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
Ü |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#ifndef _USUAL_TIME_H_ |
| 25 |
#define _USUAL_TIME_H_ |
| 26 |
|
| 27 |
#include <usual/base.h> |
| 28 |
|
| 29 |
#ifdef HAVE_SYS_TIME_H |
| 30 |
#include <sys/time.h> |
| 31 |
#endif |
| 32 |
|
| 33 |
#ifdef _WIN32 |
| 34 |
#include <winsock2.h> |
| 35 |
#endif |
| 36 |
|
| 37 |
#include <time.h> |
| 38 |
|
| 39 |
|
| 40 |
typedef uint64_t usec_t; |
| 41 |
|
| 42 |
|
| 43 |
#define USEC ((usec_t)1000000) |
| 44 |
|
| 45 |
|
| 46 |
char *format_time_ms(usec_t time, char *dest, unsigned destlen); |
| 47 |
|
| 48 |
char *format_time_s(usec_t time, char *dest, unsigned destlen); |
| 49 |
|
| 50 |
|
| 51 |
usec_t get_time_usec(void); |
| 52 |
|
| 53 |
|
| 54 |
usec_t get_cached_time(void); |
| 55 |
|
| 56 |
void reset_time_cache(void); |
| 57 |
|
| 58 |
#ifdef WIN32 |
| 59 |
|
| 60 |
|
| 61 |
#ifndef HAVE_GETTIMEOFDAY |
| 62 |
#define gettimeofday(t,z) usual_gettimeofday(t,z) |
| 63 |
|
| 64 |
|
| 65 |
int gettimeofday(struct timeval * tp, void * tzp); |
| 66 |
|
| 67 |
#endif |
| 68 |
|
| 69 |
|
| 70 |
#ifndef HAVE_LOCALTIME_R |
| 71 |
#define localtime_r(t,r) usual_localtime_r(t,r) |
| 72 |
|
| 73 |
|
| 74 |
struct tm *localtime_r(const time_t *tp, struct tm *result); |
| 75 |
|
| 76 |
#endif |
| 77 |
|
| 78 |
|
| 79 |
#ifndef HAVE_USLEEP |
| 80 |
#define usleep(x) usual_usleep(x) |
| 81 |
|
| 82 |
|
| 83 |
static inline void usleep(long usec) { Sleep(usec / 1000); } |
| 84 |
|
| 85 |
#endif |
| 86 |
|
| 87 |
#ifndef HAVE_GETRUSAGE |
| 88 |
#define getrusage(w,r) usual_getrusage(w,r) |
| 89 |
|
| 90 |
#define RUSAGE_SELF 0 |
| 91 |
|
| 92 |
|
| 93 |
struct rusage { |
| 94 |
struct timeval ru_utime; |
| 95 |
struct timeval ru_stime; |
| 96 |
}; |
| 97 |
|
| 98 |
|
| 99 |
int getrusage(int who, struct rusage *r_usage); |
| 100 |
|
| 101 |
#endif |
| 102 |
|
| 103 |
#endif |
| 104 |
|
| 105 |
#ifndef HAVE_TIMEGM |
| 106 |
#define timegm(tm) usual_timegm(tm) |
| 107 |
|
| 108 |
|
| 109 |
time_t timegm(struct tm *tm); |
| 110 |
|
| 111 |
#endif |
| 112 |
|
| 113 |
#endif |