87 lines
2.5 KiB
C
87 lines
2.5 KiB
C
#ifndef _TIME_H
|
|
#define _TIME_H
|
|
|
|
#include <stddef.h>
|
|
#include <sys/time.h>
|
|
#include <sys/types.h>
|
|
|
|
// Structure representing broken-down time.
|
|
struct tm
|
|
{
|
|
int tm_sec;
|
|
int tm_min;
|
|
int tm_hour;
|
|
int tm_mday;
|
|
int tm_mon;
|
|
int tm_year;
|
|
int tm_wday;
|
|
int tm_yday;
|
|
int tm_isdst;
|
|
};
|
|
|
|
// Captures elapsed time with nanosecond precision.
|
|
struct timespec
|
|
{
|
|
time_t tv_sec;
|
|
long tv_nsec;
|
|
};
|
|
|
|
#define CLOCKS_PER_SEC 10000000 // Number of clock_t per second.
|
|
|
|
#define CLOCK_REALTIME 0
|
|
#define CLOCK_MONOTONIC 1
|
|
#define CLOCK_PROCTIME 2
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
/* Returns a number representing how much CPU time has been used by this process. Divide this by CLOCKS_PER_SEC to
|
|
* get the value in seconds. */
|
|
clock_t clock(void);
|
|
|
|
/* Returns the current UNIX time in seconds, which is also stored in tloc if it is nonnull. */
|
|
time_t time(time_t* tloc);
|
|
|
|
/* Retrieves precise time from a specific system clock. */
|
|
int clock_gettime(clockid_t clock_id, struct timespec* tp);
|
|
|
|
/* Converts the UNIX timestamp time to broken-down time in UTC. */
|
|
struct tm* gmtime(const time_t* time);
|
|
|
|
/* Converts the UNIX timestamp time to broken-down time in UTC. Thread-safe. */
|
|
struct tm* gmtime_r(const time_t* time, struct tm* result);
|
|
|
|
/* Converts the UNIX timestamp time to broken-down time in local time. */
|
|
struct tm* localtime(const time_t* time);
|
|
|
|
/* Converts the UNIX timestamp time to broken-down time in local time. Thread-safe. */
|
|
struct tm* localtime_r(const time_t* time, struct tm* result);
|
|
|
|
/* Returns a string representation of the broken-down time in the time structure. */
|
|
char* asctime(const struct tm* time);
|
|
|
|
/* Fills buf with the string representation of the broken-down time in the time structure. Thread-safe. */
|
|
char* asctime_r(const struct tm* time, char buf[26]);
|
|
|
|
/* Returns a string representation of time. */
|
|
char* ctime(const time_t* time);
|
|
|
|
/* Fills buf with a string representation of time. Thread-safe. */
|
|
char* ctime_r(const time_t* time, char buf[26]);
|
|
|
|
/* Returns the UNIX timestamp representation of the broken-down time in the time structure. */
|
|
time_t mktime(struct tm* time);
|
|
|
|
/* Fills str with a formatted string representation of time according to the format string. */
|
|
size_t strftime(char* str, size_t max, const char* format, const struct tm* time);
|
|
|
|
/* Returns the difference between two times. */
|
|
double difftime(time_t time2, time_t time1);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif |