This is a safe version of localtime() which contains no locks and is * fork() friendly. Even the _r version of localtime() cannot be used safely * in Redis. Another thread may be calling localtime() while the main thread * forks(). Later when the child process calls localtime() again, for instance * in order to log something to the Redis log, it may deadlock: in the copy * of the address spac
| 50 | * designed to work with what time(NULL) may return, and to support Redis |
| 51 | * logging of the dates, it's not really a complete implementation. */ |
| 52 | static int is_leap_year(time_t year) { |
| 53 | if (year % 4) return 0; /* A year not divisible by 4 is not leap. */ |
| 54 | else if (year % 100) return 1; /* If div by 4 and not 100 is surely leap. */ |
| 55 | else if (year % 400) return 0; /* If div by 100 *and* not by 400 is not leap. */ |
| 56 | else return 1; /* If div by 100 and 400 is leap. */ |
| 57 | } |
| 58 | |
| 59 | void nolocks_localtime(struct tm *tmp, time_t t, time_t tz, int dst) { |
| 60 | const time_t secs_min = 60; |