2010-11-04 00:46:47 +03:00
|
|
|
/*
|
2012-07-19 22:11:40 +04:00
|
|
|
* Copyright 2002-2012 Haiku, Inc. All Rights Reserved.
|
2010-11-04 00:46:47 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2002-10-28 21:34:45 +03:00
|
|
|
#ifndef _SYS_TIME_H
|
|
|
|
#define _SYS_TIME_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
|
|
|
|
struct timeval {
|
2002-10-30 05:28:09 +03:00
|
|
|
time_t tv_sec; /* seconds */
|
|
|
|
suseconds_t tv_usec; /* microseconds */
|
2002-10-28 21:34:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#include <sys/select.h>
|
|
|
|
/* circular dependency: fd_set needs to be defined and the
|
|
|
|
* select prototype exported by this file, but <sys/select.h>
|
|
|
|
* needs struct timeval.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct timezone {
|
|
|
|
int tz_minuteswest;
|
|
|
|
int tz_dsttime;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct itimerval {
|
|
|
|
struct timeval it_interval;
|
|
|
|
struct timeval it_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ITIMER_REAL 1 /* real time */
|
|
|
|
#define ITIMER_VIRTUAL 2 /* process virtual time */
|
|
|
|
#define ITIMER_PROF 3 /* both */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern int getitimer(int which, struct itimerval *value);
|
|
|
|
extern int setitimer(int which, const struct itimerval *value, struct itimerval *oldValue);
|
2010-08-04 03:02:57 +04:00
|
|
|
extern int gettimeofday(struct timeval *tv, void *tz);
|
2002-10-28 21:34:45 +03:00
|
|
|
|
2017-11-16 09:38:16 +03:00
|
|
|
extern int utimes(const char *path, const struct timeval times[2]);
|
2002-10-28 21:34:45 +03:00
|
|
|
/* legacy */
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-03-30 21:28:31 +04:00
|
|
|
/* BSDish macros operating on timeval structs */
|
|
|
|
#define timeradd(a, b, res) \
|
|
|
|
do { \
|
|
|
|
(res)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
|
|
|
|
(res)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
|
|
|
|
if ((res)->tv_usec >= 1000000) { \
|
|
|
|
(res)->tv_usec -= 1000000; \
|
|
|
|
(res)->tv_sec++; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#define timersub(a, b, res) \
|
|
|
|
do { \
|
|
|
|
(res)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
|
|
|
|
(res)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
|
|
|
|
if ((res)->tv_usec < 0) { \
|
|
|
|
(res)->tv_usec += 1000000; \
|
|
|
|
(res)->tv_sec--; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#define timerclear(a) ((a)->tv_sec = (a)->tv_usec = 0)
|
|
|
|
#define timerisset(a) ((a)->tv_sec != 0 || (a)->tv_usec != 0)
|
|
|
|
#define timercmp(a, b, cmp) ((a)->tv_sec == (b)->tv_sec \
|
|
|
|
? (a)->tv_usec cmp (b)->tv_usec : (a)->tv_sec cmp (b)->tv_sec)
|
|
|
|
|
2002-10-28 21:34:45 +03:00
|
|
|
#endif /* _SYS_TIME_H */
|