2009-04-11 03:17:13 +08:00
|
|
|
/*****************************************************************************
|
|
|
|
* gmtime_r.c: POSIX gmtime_r() replacement
|
|
|
|
*****************************************************************************
|
2012-04-17 04:26:25 +08:00
|
|
|
* Copyright © 2011-2012 Rémi Denis-Courmont
|
2009-04-11 03:17:13 +08:00
|
|
|
*
|
Compat: relicense some functions to LGPL
asprintf, atof, atoll, gmtime_r, lldiv, rewind, strdup, strndup,
strnlen, strtof, strcasecmp
Mostly thanks to Rémi Denis-Courmont.
Some code was inspired from older VLC core code and sometimes trivial.
The old code was done by:
- Laurent Aimar
- Samuel Hocevar
- Derk-Jan Hartman
- Gildas Bazin
2011-10-05 03:46:03 +08:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2.1 of the License, or
|
2009-04-11 03:17:13 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
LGPL
Re-license almost all of libVLC and libVLCcore to LGPLv2.1+
This move was authorized by the developers, either:
- by e-mail,
- by vote at the VideoLAN Dev Days 2011,
- on the license website,
- in a contract, oral or written.
No objection was raised, so far.
The developers agreeing are:
Justus Piater
Alexis Ballier
Alexander Bethke
Mohammed Adnène Trojette
Alex Converse
Alexey Sokolov
Alexis de Lattre
Andre Pang
Anthony Loiseau
Cyril Deguet
André Weber
Boris Dorès
Brieuc Jeunhomme
Benjamin Drung
Hugo Beauzée-Luyssen
Benoit Steiner
Benjamin Pracht
Bernie Purcell
Przemyslaw Fiala
Arnaud de Bossoreille de Ribou
Brad Smith
Nick Briggs
Christopher Rath
Christophe Courtaut
Christopher Mueller
Clement Chesnin
Andres Krapf
Damien Fouilleul
David Flynn
Sebastien Zwickert
Antoine Cellerier
Jérôme Decoodt
Jérome Decoodt
Dylan Yudaken
Eduard Babayan
Eugenio Jarosiewicz
Elliot Murphy
Eric Petit
Erwan Tulou
Etienne Membrives
Ludovic Fauvet
Fabio Ritrovato
Tobias Güntner
Jakub Wieczorek
Frédéric Crozat
Francois Cartegnie
Laurent Aimar
Florian G. Pflug
Felix Paul Kühne
Frank Enderle
Rafaël Carré
Simon Latapie
Gildas Bazin
Geoffroy Couprie
Julien / Gellule
Gildas Bazin
Arnaud Schauly
Toralf Niebuhr
Vicente Jimenez Aguilar
Derk-Jan Hartman
Henri Fallon
Ilkka Ollakka
Olivier Teulière
Rémi Duraffort
Jakob Leben
Jean-Baptiste Kempf
Jean-Paul Saman
Jean-Philippe Grimaldi
Jean-François Massol
Gaël Hendryckx
Jakob Leben
Jean-Marc Dressler
Jai Menon
Johan Bilien
Johann Ransay
Joris van Rooij
JP Dinger
Jean-Philippe André
Adrien Grand
Juha Jeronen
Juho Vähä-Herttua
Kaarlo Raiha
Kaarlo Raiha
Kamil Baldyga
Keary Griffin
Ken Self
KO Myung-Hun
Pierre Ynard
Filippo Carone
Loïc Minier
Luca Barbato
Lucas C. Villa Real
Lukas Durfina
Adrien Maglo
Marc Ariberti
Mark Lee
Mark Moriarty
Martin Storsjö
Christophe Massiot
Michel Kaempf
Marian Ďurkovič
Mirsal Ennaime
Carlo Calabrò
Damien Lucas
Naohiro Koriyama
Basos G
Pierre Baillet
Vincent Penquerc'h
Olivier Aubert
Pankaj Yadav
Paul Corke
Pierre d'Herbemont
Philippe Morin
Antoine Lejeune
Michael Ploujnikov
Jean-Marc Dressler
Michael Hanselmann
Rafaël Carré
Ramiro Polla
Rémi Denis-Courmont
Renaud Dartus
Richard Shepherd
Faustino Osuna
Arnaud Vallat
Rob Jonson
Robert Jedrzejczyk
Steve Lhomme
Rocky Bernstein
Romain Goyet
Rov Juvano
Sam Hocevar
Martin T. H. Sandsmark
Sebastian Birk
Sébastien Escudier
Vincent Seguin
Fabio Ritrovato
Sigmund Augdal Helberg
Casian Andrei
Srikanth Raju
Hannes Domani
Stéphane Borel
Stephan Krempel
Stephan Assmus
Tony Castley
Pavlov Konstantin
Eric Petit
Tanguy Krotoff
Dennis van Amerongen
Michel Lespinasse
Can Wu
Xavier Marchesini
Sébastien Toque
Christophe Mutricy
Yoann Peronneau
Yohann Martineau
Yuval Tze
Scott Caudle
Clément Stenac
It is possible, that some minor piece of code was badly tracked, for
some reasons (SVN, mainly) or that some small developers did not answer.
However, as an "œuvre collective", defined as in "CPI 113-2 alinéa 3",
and seeing "Cour. Cass. 17 Mai 1978", and seeing that the editor and
the very vast majority of developers have agreed (> 99.99% of the code,
> 99% of developers), we are fine here.
2011-11-28 04:44:15 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Compat: relicense some functions to LGPL
asprintf, atof, atoll, gmtime_r, lldiv, rewind, strdup, strndup,
strnlen, strtof, strcasecmp
Mostly thanks to Rémi Denis-Courmont.
Some code was inspired from older VLC core code and sometimes trivial.
The old code was done by:
- Laurent Aimar
- Samuel Hocevar
- Derk-Jan Hartman
- Gildas Bazin
2011-10-05 03:46:03 +08:00
|
|
|
* GNU Lesser General Public License for more details.
|
2009-04-11 03:17:13 +08:00
|
|
|
*
|
Compat: relicense some functions to LGPL
asprintf, atof, atoll, gmtime_r, lldiv, rewind, strdup, strndup,
strnlen, strtof, strcasecmp
Mostly thanks to Rémi Denis-Courmont.
Some code was inspired from older VLC core code and sometimes trivial.
The old code was done by:
- Laurent Aimar
- Samuel Hocevar
- Derk-Jan Hartman
- Gildas Bazin
2011-10-05 03:46:03 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
|
2009-04-11 03:17:13 +08:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <time.h>
|
2012-04-17 04:26:25 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2009-04-11 03:17:13 +08:00
|
|
|
|
2012-04-17 04:26:25 +08:00
|
|
|
struct tm *gmtime_r (const time_t *timep, struct tm *tm)
|
2009-04-11 03:17:13 +08:00
|
|
|
{
|
2023-01-16 16:38:14 +08:00
|
|
|
#if defined (_WIN32)
|
|
|
|
errno_t ret = gmtime_s(tm, timep);
|
|
|
|
if (ret == 0)
|
|
|
|
return tm;
|
|
|
|
errno = ret;
|
|
|
|
return NULL;
|
|
|
|
#else // !_WIN32
|
2012-04-17 04:26:25 +08:00
|
|
|
static const unsigned short normal[12] =
|
|
|
|
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
|
|
|
static const unsigned short leap[12] =
|
|
|
|
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
|
|
|
lldiv_t d;
|
|
|
|
const unsigned short *months;
|
2009-04-11 03:17:13 +08:00
|
|
|
|
2012-04-17 04:26:25 +08:00
|
|
|
/* Rebase from 1970 Unix epoch to fictitious year 0 (i.e. would-be
|
|
|
|
* year 1 BC had the Gregorian calendar already existed then) */
|
|
|
|
d.quot = 60LL * 60 * 24 * (4 * 146097 + 135140) + *timep;
|
|
|
|
|
|
|
|
d = lldiv (d.quot, 60); /* 60 seconds per minute */
|
|
|
|
if (*timep < 0)
|
|
|
|
{
|
|
|
|
d.rem += 60;
|
|
|
|
d.quot--;
|
|
|
|
}
|
|
|
|
tm->tm_sec = d.rem;
|
|
|
|
|
|
|
|
d = lldiv (d.quot, 60); /* 60 minutes per hour */
|
|
|
|
tm->tm_min = d.rem;
|
|
|
|
|
|
|
|
d = lldiv (d.quot, 24); /* 24 hours per day */
|
|
|
|
tm->tm_hour = d.rem;
|
|
|
|
|
|
|
|
tm->tm_wday = (d.quot + 6) % 7; /* 7 days per week */
|
|
|
|
|
|
|
|
d = lldiv (d.quot, 146097); /* 146097 days per 4 centuries */
|
|
|
|
tm->tm_year = 400 * d.quot;
|
|
|
|
|
|
|
|
if (d.rem >= 36525)
|
|
|
|
{ /* Century with 24 leap years */
|
|
|
|
d.rem -= 36525;
|
|
|
|
tm->tm_year += 100;
|
|
|
|
|
|
|
|
d = lldiv (d.rem, 36524); /* 36524 days per normal century */
|
|
|
|
tm->tm_year += d.quot * 100;
|
|
|
|
if (d.rem >= 59) /* not in January or February of year 00 */
|
|
|
|
d.rem++; /* insert missing February 29th 00*/
|
|
|
|
}
|
|
|
|
tm->tm_year -= 1900; /* Rebase to 1900 for struct tm */
|
|
|
|
|
|
|
|
d = lldiv (d.rem, 1461); /* 1461 days per 4 years */
|
|
|
|
tm->tm_year += 4 * d.quot;
|
|
|
|
|
|
|
|
if (d.rem >= 366)
|
|
|
|
{ /* Non-leap year */
|
|
|
|
d.rem -= 366;
|
|
|
|
tm->tm_year++;
|
|
|
|
|
|
|
|
d = lldiv (d.rem, 365); /* 365 days per normal year */
|
|
|
|
tm->tm_year += d.quot;
|
|
|
|
months = normal;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
months = leap;
|
|
|
|
tm->tm_yday = d.rem;
|
|
|
|
|
|
|
|
for (tm->tm_mon = 0; d.rem >= months[tm->tm_mon]; tm->tm_mon++)
|
|
|
|
d.rem -= months[tm->tm_mon]; /* 28 to 31 days in a month */
|
|
|
|
tm->tm_mday = d.rem + 1;
|
|
|
|
|
|
|
|
tm->tm_isdst = 0; /* UTC time */
|
|
|
|
return tm;
|
2023-01-16 16:38:14 +08:00
|
|
|
#endif // !_WIN32
|
2009-04-11 03:17:13 +08:00
|
|
|
}
|