-/* This is a wrapper for gettimeofday. It is used only on systems for which
- gettimeofday clobbers the static buffer used for localtime's result.
+/* Same as above, since gmtime and localtime use the same buffer. */
+struct tm *
+gmtime (time_t const *timep)
+{
+#undef gmtime
+ extern struct tm *gmtime (time_t const *);
+ struct tm *tm = gmtime (timep);
+
+ if (localtime_buffer_addr == &tm_zero_buffer)
+ localtime_buffer_addr = tm;
+
+ return tm;
+}
+
+#endif /* GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME */
+
+#if TZSET_CLOBBERS_LOCALTIME
+/* This is a wrapper for tzset, for systems on which tzset may clobber
+ the static buffer used for localtime's result. */
+void
+tzset (void)
+{
+#undef tzset
+ extern void tzset (void);
+
+ /* Save and restore the contents of the buffer used for localtime's
+ result around the call to tzset. */
+ struct tm save = *localtime_buffer_addr;
+ tzset ();
+ *localtime_buffer_addr = save;
+}
+#endif