Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
c05b7fdf
Commit
c05b7fdf
authored
Apr 16, 2012
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gmtime_r: rewrite, now truly thread-safe
parent
c086f181
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
7 deletions
+67
-7
compat/gmtime_r.c
compat/gmtime_r.c
+67
-7
No files found.
compat/gmtime_r.c
View file @
c05b7fdf
/*****************************************************************************
/*****************************************************************************
* gmtime_r.c: POSIX gmtime_r() replacement
* gmtime_r.c: POSIX gmtime_r() replacement
*****************************************************************************
*****************************************************************************
* Copyright ©
1998-2008 VLC authors and VideoLAN
* Copyright ©
2011-2012 Rémi Denis-Courmont
*
*
* This program is free software; you can redistribute it and/or modify it
* 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
* under the terms of the GNU Lesser General Public License as published by
...
@@ -23,13 +23,73 @@
...
@@ -23,13 +23,73 @@
#endif
#endif
#include <time.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
struct
tm
*
gmtime_r
(
const
time_t
*
timep
,
struct
tm
*
result
)
struct
tm
*
gmtime_r
(
const
time_t
*
timep
,
struct
tm
*
tm
)
{
{
struct
tm
*
s
=
gmtime
(
timep
);
static
const
unsigned
short
normal
[
12
]
=
if
(
s
==
NULL
)
{
31
,
28
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
};
return
NULL
;
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
;
*
result
=
*
s
;
/* Rebase from 1970 Unix epoch to fictitious year 0 (i.e. would-be
return
result
;
* 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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment