Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.15.12 ]​[ nginx-1.16.0 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #include <ngx_config.h>
0009 #include <ngx_core.h>
0010 
0011 
0012 /*
0013  * FreeBSD does not test /etc/localtime change, however, we can workaround it
0014  * by calling tzset() with TZ and then without TZ to update timezone.
0015  * The trick should work since FreeBSD 2.1.0.
0016  *
0017  * Linux does not test /etc/localtime change in localtime(),
0018  * but may stat("/etc/localtime") several times in every strftime(),
0019  * therefore we use it to update timezone.
0020  *
0021  * Solaris does not test /etc/TIMEZONE change too and no workaround available.
0022  */
0023 
0024 void
0025 ngx_timezone_update(void)
0026 {
0027 #if (NGX_FREEBSD)
0028 
0029     if (getenv("TZ")) {
0030         return;
0031     }
0032 
0033     putenv("TZ=UTC");
0034 
0035     tzset();
0036 
0037     unsetenv("TZ");
0038 
0039     tzset();
0040 
0041 #elif (NGX_LINUX)
0042     time_t      s;
0043     struct tm  *t;
0044     char        buf[4];
0045 
0046     s = time(0);
0047 
0048     t = localtime(&s);
0049 
0050     strftime(buf, 4, "%H", t);
0051 
0052 #endif
0053 }
0054 
0055 
0056 void
0057 ngx_localtime(time_t s, ngx_tm_t *tm)
0058 {
0059 #if (NGX_HAVE_LOCALTIME_R)
0060     (void) localtime_r(&s, tm);
0061 
0062 #else
0063     ngx_tm_t  *t;
0064 
0065     t = localtime(&s);
0066     *tm = *t;
0067 
0068 #endif
0069 
0070     tm->ngx_tm_mon++;
0071     tm->ngx_tm_year += 1900;
0072 }
0073 
0074 
0075 void
0076 ngx_libc_localtime(time_t s, struct tm *tm)
0077 {
0078 #if (NGX_HAVE_LOCALTIME_R)
0079     (void) localtime_r(&s, tm);
0080 
0081 #else
0082     struct tm  *t;
0083 
0084     t = localtime(&s);
0085     *tm = *t;
0086 
0087 #endif
0088 }
0089 
0090 
0091 void
0092 ngx_libc_gmtime(time_t s, struct tm *tm)
0093 {
0094 #if (NGX_HAVE_LOCALTIME_R)
0095     (void) gmtime_r(&s, tm);
0096 
0097 #else
0098     struct tm  *t;
0099 
0100     t = gmtime(&s);
0101     *tm = *t;
0102 
0103 #endif
0104 }