1 /* Convert `time_t' to `struct tm' in local time zone.
2 Copyright (C) 1991, 92, 93, 95, 96, 97 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
22 #include <libc-lock.h>
24 /* The C Standard says that localtime and gmtime return the same pointer. */
27 /* Prototype for the internal function to get information based on TZ. */
28 extern void __tzset_internal
__P ((int always
));
29 extern int __tz_compute
__P ((time_t timer
, struct tm
*tp
));
30 extern int __tzfile_compute
__P ((time_t timer
,
31 long int *leap_correct
, int *leap_hit
));
33 extern int __use_tzfile
;
35 /* This lock is defined in tzset.c and locks all the data defined there
36 and in tzfile.c; the internal functions do no locking themselves.
37 This lock is only taken here and in `tzset'. */
38 __libc_lock_define (extern, __tzset_lock
)
41 /* Return the `struct tm' representation of *TIMER in the local timezone. */
43 localtime_internal (const time_t *timer
, struct tm
*tp
)
45 long int leap_correction
;
56 if (! __tzfile_compute (*timer
, &leap_correction
, &leap_extra_secs
))
61 tp
= __gmtime_r (timer
, tp
);
62 if (tp
&& ! __tz_compute (*timer
, tp
))
70 __offtime (timer
, __timezone
- leap_correction
, tp
);
71 tp
->tm_sec
+= leap_extra_secs
;
72 tp
->tm_isdst
= __daylight
;
73 tp
->tm_gmtoff
= __timezone
;
74 tp
->tm_zone
= __tzname
[__daylight
];
81 /* POSIX.1 8.3.7.2 says that localtime_r is not required to set
82 tzname. This is a good idea since this allows at least a bit more
91 __libc_lock_lock (__tzset_lock
);
93 /* Update internal database according to current TZ setting. */
96 result
= localtime_internal (timer
, &_tmbuf
);
98 __libc_lock_unlock (__tzset_lock
);
105 __localtime_r (timer
, tp
)
111 __libc_lock_lock (__tzset_lock
);
113 /* Make sure the database is initialized. */
114 __tzset_internal (0);
116 result
= localtime_internal (timer
, tp
);
118 __libc_lock_unlock (__tzset_lock
);
122 weak_alias (__localtime_r
, localtime_r
)