time.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <sys/cdefs.h>
  8. #include <sys/types.h>
  9. __BEGIN_DECLS
  10. struct tm {
  11. int tm_sec; /* Seconds (0-60) */
  12. int tm_min; /* Minutes (0-59) */
  13. int tm_hour; /* Hours (0-23) */
  14. int tm_mday; /* Day of the month (1-31) */
  15. int tm_mon; /* Month (0-11) */
  16. int tm_year; /* Year - 1900 */
  17. int tm_wday; /* Day of the week (0-6, Sunday = 0) */
  18. int tm_yday; /* Day in the year (0-365, 1 Jan = 0) */
  19. int tm_isdst; /* Daylight saving time */
  20. };
  21. extern long timezone; /* The difference in seconds between UTC and local time */
  22. extern long altzone;
  23. extern char* tzname[2];
  24. extern int daylight;
  25. typedef uint32_t clock_t;
  26. typedef int64_t time_t;
  27. struct tm* localtime(const time_t*);
  28. struct tm* gmtime(const time_t*);
  29. time_t mktime(struct tm*);
  30. time_t timegm(struct tm*);
  31. time_t time(time_t*);
  32. char* ctime(const time_t*);
  33. char* ctime_r(const time_t* tm, char* buf);
  34. void tzset();
  35. char* asctime(const struct tm*);
  36. char* asctime_r(const struct tm*, char* buf);
  37. #define CLOCKS_PER_SEC 1000
  38. clock_t clock();
  39. struct timespec {
  40. time_t tv_sec;
  41. long tv_nsec;
  42. };
  43. typedef int clockid_t;
  44. #define CLOCK_REALTIME 0
  45. #define CLOCK_MONOTONIC 1
  46. #define CLOCK_MONOTONIC_RAW 4
  47. #define CLOCK_REALTIME_COARSE 5
  48. #define CLOCK_MONOTONIC_COARSE 6
  49. #define TIMER_ABSTIME 99
  50. int clock_gettime(clockid_t, struct timespec*);
  51. int clock_settime(clockid_t, struct timespec*);
  52. int clock_nanosleep(clockid_t, int flags, const struct timespec* requested_sleep, struct timespec* remaining_sleep);
  53. int clock_getres(clockid_t, struct timespec* result);
  54. int nanosleep(const struct timespec* requested_sleep, struct timespec* remaining_sleep);
  55. struct tm* gmtime_r(const time_t* timep, struct tm* result);
  56. struct tm* localtime_r(const time_t* timep, struct tm* result);
  57. double difftime(time_t, time_t);
  58. size_t strftime(char* s, size_t max, const char* format, const struct tm*) __attribute__((format(strftime, 3, 0)));
  59. __END_DECLS