1 /* localtime -- convert `time_t' to `struct tm' in local time zone
2 Copyright (C) 1991, 92, 93, 95, 96 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
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
22 #include <libc-lock.h>
24 /* The C Standard says that localtime and gmtime return the same pointer. */
27 /* Return the `struct tm' representation of *TIMER in the local timezone. */
32 return __localtime_r (timer
, &_tmbuf
);
36 __localtime_r (timer
, tp
)
40 /* This lock is defined in tzset.c and locks all the data defined there
41 and in tzfile.c; the internal functions do no locking themselves.
42 This lock is only taken here and in `tzset'. */
43 extern int __tzset_run
, __use_tzfile
;
44 extern int __tz_compute
__P ((time_t timer
, struct tm
*tp
));
45 extern int __tzfile_compute
__P ((time_t timer
,
46 long int *leap_correct
, int *leap_hit
));
47 long int leap_correction
;
49 __libc_lock_define (extern, __tzset_lock
);
57 __libc_lock_lock (__tzset_lock
);
59 /* Make sure the database is initialized. */
65 if (! __tzfile_compute (*timer
, &leap_correction
, &leap_extra_secs
))
70 tp
= __gmtime_r (timer
, tp
);
71 if (tp
&& ! __tz_compute (*timer
, tp
))
79 __offtime (timer
, __timezone
- leap_correction
, tp
);
80 tp
->tm_sec
+= leap_extra_secs
;
81 tp
->tm_isdst
= __daylight
;
82 tp
->tm_gmtoff
= __timezone
;
83 tp
->tm_zone
= __tzname
[__daylight
];
86 __libc_lock_unlock (__tzset_lock
);
90 weak_alias (__localtime_r
, localtime_r
)