Blame src/gl/localtime-buffer.c

Packit aea12f
/* Provide access to the last buffer returned by localtime() or gmtime().
Packit aea12f
Packit Service 991b93
   Copyright (C) 2001-2003, 2005-2007, 2009-2020 Free Software Foundation, Inc.
Packit aea12f
Packit aea12f
   This program is free software; you can redistribute it and/or modify
Packit aea12f
   it under the terms of the GNU General Public License as published by
Packit aea12f
   the Free Software Foundation; either version 3, or (at your option)
Packit aea12f
   any later version.
Packit aea12f
Packit aea12f
   This program is distributed in the hope that it will be useful,
Packit aea12f
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit aea12f
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit aea12f
   GNU General Public License for more details.
Packit aea12f
Packit aea12f
   You should have received a copy of the GNU General Public License
Packit aea12f
   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
Packit aea12f
Packit aea12f
/* written by Jim Meyering */
Packit aea12f
Packit aea12f
#include <config.h>
Packit aea12f
Packit aea12f
/* Specification.  */
Packit aea12f
#include "localtime-buffer.h"
Packit aea12f
Packit aea12f
#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME
Packit aea12f
Packit aea12f
static struct tm tm_zero_buffer;
Packit aea12f
struct tm *localtime_buffer_addr = &tm_zero_buffer;
Packit aea12f
Packit aea12f
/* This is a wrapper for localtime.
Packit aea12f
Packit aea12f
   On the first call, record the address of the static buffer that
Packit aea12f
   localtime uses for its result.  */
Packit aea12f
Packit aea12f
struct tm *
Packit aea12f
rpl_localtime (time_t const *timep)
Packit aea12f
#undef localtime
Packit aea12f
{
Packit aea12f
  struct tm *tm = localtime (timep);
Packit aea12f
Packit aea12f
  if (localtime_buffer_addr == &tm_zero_buffer)
Packit aea12f
    localtime_buffer_addr = tm;
Packit aea12f
Packit aea12f
  return tm;
Packit aea12f
}
Packit aea12f
Packit aea12f
/* Same as above, since gmtime and localtime use the same buffer.  */
Packit aea12f
struct tm *
Packit aea12f
rpl_gmtime (time_t const *timep)
Packit aea12f
#undef gmtime
Packit aea12f
{
Packit aea12f
  struct tm *tm = gmtime (timep);
Packit aea12f
Packit aea12f
  if (localtime_buffer_addr == &tm_zero_buffer)
Packit aea12f
    localtime_buffer_addr = tm;
Packit aea12f
Packit aea12f
  return tm;
Packit aea12f
}
Packit aea12f
Packit aea12f
#endif