Mercurial > dovecot > originalhg > dovecot1.2
annotate src/lib/utcmktime.c @ 9191:b340ecb24469 HEAD
Fix VPATH build of RQUOTA support.
Some rpcgen derive #include "..." paths from the infile argument.
This will be off for VPATH builds, as the generated rquota_xdr.c
code will look in $(srcdir), but we'll generate the rquota.h file in
$(builddir). Play safe and copy rquota.x to $(builddir) first.
This fixes the build on openSUSE 11.1.
author  Matthias Andree <matthias.andree@gmx.de> 

date  Tue, 07 Jul 2009 21:01:36 +0200 
parents  b9faf4db2a9f 
children  00cd9aacd03c 
rev  line source 

8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset

1 /* Copyright (c) 20072009 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 
1658
20519e4bca48
utc_mktime() crashed with 64bit time_t if gmtime() didn't like >32bit values
Timo Sirainen <tss@iki.fi>
parents:
493
diff
changeset

3 #include "lib.h" 
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset

4 #include "utcmktime.h" 
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset

5 
6483
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

6 static int tm_cmp(const struct tm *tm1, const struct tm *tm2) 
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset

7 { 
6483
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

8 int diff; 
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset

9 
6483
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

10 if ((diff = tm1>tm_year  tm2>tm_year) != 0) 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

11 return diff; 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

12 if ((diff = tm1>tm_mon  tm2>tm_mon) != 0) 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

13 return diff; 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

14 if ((diff = tm1>tm_mday  tm2>tm_mday) != 0) 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

15 return diff; 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

16 if ((diff = tm1>tm_hour  tm2>tm_hour) != 0) 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

17 return diff; 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

18 if ((diff = tm1>tm_min  tm2>tm_min) != 0) 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

19 return diff; 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

20 return tm1>tm_sec  tm2>tm_sec; 
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset

21 } 
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset

22 
6483
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

23 time_t utc_mktime(const struct tm *tm) 
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset

24 { 
6483
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

25 const struct tm *try_tm; 
6597  26 time_t t; 
6483
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

27 int bits, dir; 
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset

28 
6483
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

29 /* we'll do a binary search across the entire valid time_t range. 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

30 when gmtime()'s output matches the tm parameter, we've found the 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

31 correct time_t value. this also means that if tm contains invalid 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

32 values, 1 is returned. */ 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

33 #ifdef TIME_T_SIGNED 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

34 t = 0; 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

35 #else 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

36 t = 1 << (TIME_T_MAX_BITS  1); 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

37 #endif 
6584
4fb613eb8ce9
utc_mktime() was broken with 32bit time_t. Also don't try to optimize away
Timo Sirainen <tss@iki.fi>
parents:
6483
diff
changeset

38 for (bits = TIME_T_MAX_BITS  2;; bits) { 
6483
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

39 try_tm = gmtime(&t); 
6584
4fb613eb8ce9
utc_mktime() was broken with 32bit time_t. Also don't try to optimize away
Timo Sirainen <tss@iki.fi>
parents:
6483
diff
changeset

40 dir = tm_cmp(tm, try_tm); 
6483
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

41 if (dir == 0) 
6584
4fb613eb8ce9
utc_mktime() was broken with 32bit time_t. Also don't try to optimize away
Timo Sirainen <tss@iki.fi>
parents:
6483
diff
changeset

42 return t; 
6483
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

43 if (bits < 0) 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

44 break; 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

45 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

46 if (dir < 0) 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

47 t = (time_t)1 << bits; 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

48 else 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

49 t += (time_t)1 << bits; 
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset

50 } 
6483
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

51 
6d15946eccb5
Rewrote utc_mktime() so it's now MIT licensed. This also fixes handling
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset

52 return (time_t)1; 
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset

53 } 