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 SECS_PER_ERA TIMELIB_LL_CONST(12622780800) 85 #define SECS_PER_DAY 86400 86 #define DAYS_PER_YEAR 365 87 #define DAYS_PER_LYEAR 366 88 /* 400*365 days + 97 leap days */ 89 #define DAYS_PER_LYEAR_PERIOD 146097 90 #define YEARS_PER_LYEAR_PERIOD 400 91 92 #define TIMELIB_TZINFO_PHP 0x01 93 #define TIMELIB_TZINFO_ZONEINFO 0x02 94 95 #define timelib_is_leap(y) ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0)) 96 97 #define TIMELIB_DEBUG(s) if (0) { s } 98 99 #define TIMELIB_TIME_FREE(m) \ 100 if (m) { \ 101 timelib_free(m); \ 102 m = NULL; \ 103 } 104 105 struct _ttinfo 106 { 107 int32_t offset; 108 int isdst; 109 unsigned int abbr_idx; 110 111 unsigned int isstdcnt; 112 unsigned int isgmtcnt; 113 }; 114 115 struct _tlinfo 116 { 117 int64_t trans; 118 int32_t offset; 119 }; 120 121 122 #ifndef LONG_MAX 123 #define LONG_MAX 2147483647L 124 #endif 125 126 #ifndef LONG_MIN 127 #define LONG_MIN (- LONG_MAX - 1) 128 #endif 129 130 /* From unixtime2tm.c */ 131 int timelib_apply_localtime(timelib_time *t, unsigned int localtime); 132 133 /* From parse_tz.c */ 134 void timelib_time_tz_abbr_update(timelib_time* tm, char* tz_abbr); 135 136 /* From timelib.c */ 137 int timelib_strcasecmp(const char *s1, const char *s2); 138 int timelib_strncasecmp(const char *s1, const char *s2, size_t n); 139 140 #endif 141