1 /* Work around the bug in some systems whereby gettimeofday clobbers the
2 static buffer that localtime uses for it's return value. The gettimeofday
3 function from Mac OS X 10.0.4, i.e. Darwin 1.3.7 has this problem.
4 The tzset replacement is necessary for at least Solaris 2.5, 2.5.1, and 2.6.
5 Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
21 /* written by Jim Meyering */
27 /* Disable the definitions of these functions (from config.h)
28 so we can use the library versions here. */
34 #include <sys/types.h>
36 #if TIME_WITH_SYS_TIME
37 # include <sys/time.h>
41 # include <sys/time.h>
49 static struct tm
*localtime_buffer_addr
;
51 /* This is a wrapper for localtime. It is used only on systems for which
52 gettimeofday clobbers the static buffer used for localtime's result.
54 On the first call, record the address of the static buffer that
55 localtime uses for its result. */
58 rpl_localtime (const time_t *timep
)
60 struct tm
*tm
= localtime (timep
);
62 if (! localtime_buffer_addr
)
63 localtime_buffer_addr
= tm
;
68 /* Same as above, since gmtime and localtime use the same buffer. */
70 rpl_gmtime (const time_t *timep
)
72 struct tm
*tm
= gmtime (timep
);
74 if (! localtime_buffer_addr
)
75 localtime_buffer_addr
= tm
;
80 /* This is a wrapper for gettimeofday. It is used only on systems for which
81 gettimeofday clobbers the static buffer used for localtime's result.
83 Save and restore the contents of the buffer used for localtime's result
84 around the call to gettimeofday. */
87 rpl_gettimeofday (struct timeval
*tv
, struct timezone
*tz
)
92 if (! localtime_buffer_addr
)
95 localtime_buffer_addr
= localtime (&t
);
98 save
= *localtime_buffer_addr
;
99 result
= gettimeofday (tv
, tz
);
100 *localtime_buffer_addr
= save
;
105 /* This is a wrapper for tzset. It is used only on systems for which
106 tzset may clobber the static buffer used for localtime's result.
107 Save and restore the contents of the buffer used for localtime's
108 result around the call to tzset. */
114 if (! localtime_buffer_addr
)
117 localtime_buffer_addr
= localtime (&t
);
120 save
= *localtime_buffer_addr
;
122 *localtime_buffer_addr
= save
;