Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/utc-offset.c @ 9658:8ba4253adc9b HEAD tip
*-login: SSL connections didn't get closed when the client got destroyed.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 08 May 2014 16:41:29 +0300 |
parents | 00cd9aacd03c |
children |
rev | line source |
---|---|
9532
00cd9aacd03c
Updated copyright notices to include year 2010.
Timo Sirainen <tss@iki.fi>
parents:
9235
diff
changeset
|
1 /* Copyright (c) 2002-2010 Dovecot authors, see the included COPYING file */ |
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "utc-offset.h" |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include <sys/time.h> |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
8 int utc_offset(struct tm *tm, time_t t ATTR_UNUSED) |
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 { |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #ifdef HAVE_TM_GMTOFF |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 return (int) (tm->tm_gmtoff/60); |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 #else |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 struct tm ltm, gtm; |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 int offset; |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 /* gmtime() overwrites tm, so we need to copy it elsewhere */ |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 ltm = *tm; |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 tm = gmtime(&t); |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 gtm = *tm; |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 /* max offset of 24 hours */ |
9235
8e66ca02b6f9
utc_offset() was broken with year's first/last day if struct tm.tm_gmtoff didn't exist.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
22 if ((ltm.tm_yday < gtm.tm_yday && ltm.tm_year == gtm.tm_year) || |
8e66ca02b6f9
utc_offset() was broken with year's first/last day if struct tm.tm_gmtoff didn't exist.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
23 ltm.tm_year < gtm.tm_year) |
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 offset = -24 * 60; |
9235
8e66ca02b6f9
utc_offset() was broken with year's first/last day if struct tm.tm_gmtoff didn't exist.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
25 else if ((ltm.tm_yday > gtm.tm_yday && ltm.tm_year == gtm.tm_year) || |
8e66ca02b6f9
utc_offset() was broken with year's first/last day if struct tm.tm_gmtoff didn't exist.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
26 ltm.tm_year > gtm.tm_year) |
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 offset = 24 * 60; |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 else |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 offset = 0; |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 offset += (ltm.tm_hour - gtm.tm_hour) * 60; |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 offset += (ltm.tm_min - gtm.tm_min); |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 /* restore overwritten tm */ |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 *tm = ltm; |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 return offset; |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 #endif |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 } |