Blame gl/localtime-buffer.c

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