1 /* 2 * The MIT License (MIT) 3 * 4 * Copyright (c) 2015-2019 Derick Rethans 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 * copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 * THE SOFTWARE. 23 */ 24 25 #ifndef __TIMELIB_PRIVATE_H__ 26 #define __TIMELIB_PRIVATE_H__ 27 28 #ifdef HAVE_TIMELIB_CONFIG_H 29 # include "timelib_config.h" 30 #endif 31 32 #ifdef HAVE_SYS_TIME_H 33 # include <sys/time.h> 34 #endif 35 36 #ifdef _WIN32 37 # ifdef HAVE_WINSOCK2_H 38 # include <winsock2.h> 39 # endif 40 #endif 41 42 #include <string.h> 43 44 #ifdef HAVE_SYS_TYPES_H 45 #include <sys/types.h> 46 #endif 47 48 #if defined(HAVE_STDINT_H) 49 # include <stdint.h> 50 #endif 51 52 #if HAVE_UNISTD_H 53 # include <unistd.h> 54 #endif 55 56 #if HAVE_IO_H 57 # include <io.h> 58 #endif 59 60 #if HAVE_DIRENT_H 61 # include <dirent.h> 62 #endif 63 64 #include <stdio.h> 65 #include <limits.h> 66 67 #define TIMELIB_SECOND 1 68 #define TIMELIB_MINUTE 2 69 #define TIMELIB_HOUR 3 70 #define TIMELIB_DAY 4 71 #define TIMELIB_MONTH 5 72 #define TIMELIB_YEAR 6 73 #define TIMELIB_WEEKDAY 7 74 #define TIMELIB_SPECIAL 8 75 #define TIMELIB_MICROSEC 9 76 77 #define TIMELIB_SPECIAL_WEEKDAY 0x01 78 #define TIMELIB_SPECIAL_DAY_OF_WEEK_IN_MONTH 0x02 79 #define TIMELIB_SPECIAL_LAST_DAY_OF_WEEK_IN_MONTH 0x03 80 81 #define TIMELIB_SPECIAL_FIRST_DAY_OF_MONTH 0x01 82 #define TIMELIB_SPECIAL_LAST_DAY_OF_MONTH 0x02 83 84 #define TIMELIB_TIME_PART_DONT_KEEP 0x00 85 #define TIMELIB_TIME_PART_KEEP 0x01 86 87 #define SECS_PER_ERA TIMELIB_LL_CONST(12622780800) 88 #define SECS_PER_DAY 86400 89 #define DAYS_PER_YEAR 365 90 #define DAYS_PER_LYEAR 366 91 /* 400*365 days + 97 leap days */ 92 #define DAYS_PER_LYEAR_PERIOD 146097 93 #define YEARS_PER_LYEAR_PERIOD 400 94 95 #define TIMELIB_TZINFO_PHP 0x01 96 #define TIMELIB_TZINFO_ZONEINFO 0x02 97 98 #define timelib_is_leap(y) ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0)) 99 100 #define TIMELIB_DEBUG(s) if (0) { s } 101 102 #define TIMELIB_TIME_FREE(m) \ 103 if (m) { \ 104 timelib_free(m); \ 105 m = NULL; \ 106 } 107 108 struct _ttinfo 109 { 110 int32_t offset; 111 int isdst; 112 unsigned int abbr_idx; 113 114 unsigned int isstdcnt; 115 unsigned int isgmtcnt; 116 }; 117 118 struct _tlinfo 119 { 120 int64_t trans; 121 int32_t offset; 122 }; 123 124 125 #ifndef LONG_MAX 126 #define LONG_MAX 2147483647L 127 #endif 128 129 #ifndef LONG_MIN 130 #define LONG_MIN (- LONG_MAX - 1) 131 #endif 132 133 /* From unixtime2tm.c */ 134 int timelib_apply_localtime(timelib_time *t, unsigned int localtime); 135 136 /* From parse_tz.c */ 137 void timelib_time_tz_abbr_update(timelib_time* tm, const char* tz_abbr); 138 139 /* From timelib.c */ 140 int timelib_strcasecmp(const char *s1, const char *s2); 141 int timelib_strncasecmp(const char *s1, const char *s2, size_t n); 142 143 #endif 144