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
903664b8
Commit
903664b8
authored
Dec 10, 2015
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
compat: replace timegm()
parent
1e30d40c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
2 deletions
+79
-2
compat/timegm.c
compat/timegm.c
+72
-0
configure.ac
configure.ac
+1
-1
include/vlc_fixups.h
include/vlc_fixups.h
+6
-1
No files found.
compat/timegm.c
0 → 100644
View file @
903664b8
/*****************************************************************************
* timegm.c: BSD/GNU timegm() replacement
*****************************************************************************
* Copyright © 2007 Laurent Aimar
* Copyright © 2015 Rémi Denis-Courmont
*
* 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
* (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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* 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.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdbool.h>
#include <time.h>
static
bool
is_leap_year
(
unsigned
y
)
{
if
(
y
%
4
)
return
false
;
if
(
y
%
100
)
return
true
;
if
(
y
%
400
)
return
false
;
return
true
;
}
time_t
timegm
(
const
struct
tm
*
tm
)
{
static
const
unsigned
ydays
[
12
+
1
]
=
{
0
,
31
,
59
,
90
,
120
,
151
,
181
,
212
,
243
,
273
,
304
,
334
};
if
(
tm
->
tm_year
<
70
/* FIXME: (negative) dates before Epoch */
||
tm
->
tm_mon
<
0
||
tm
->
tm_mon
>
11
||
tm
->
tm_mday
<
1
||
tm
->
tm_mday
>
31
||
tm
->
tm_hour
<
0
||
tm
->
tm_hour
>
23
||
tm
->
tm_min
<
0
||
tm
->
tm_min
>
59
||
tm
->
tm_sec
<
0
||
tm
->
tm_sec
>
60
/* mind the leap second */
)
return
-
1
;
/* Count the number of days */
unsigned
t
=
365
*
(
tm
->
tm_year
-
70
)
+
ydays
[
tm
->
tm_mon
]
+
(
tm
->
tm_mday
-
1
);
/* TODO: unroll */
for
(
int
i
=
70
;
i
<
tm
->
tm_year
;
i
++
)
t
+=
is_leap_year
(
1900
+
i
);
if
(
tm
->
tm_mon
>
1
)
t
+=
is_leap_year
(
1900
+
tm
->
tm_year
);
t
*=
24
;
t
+=
tm
->
tm_hour
;
t
*=
60
;
t
+=
tm
->
tm_min
;
t
*=
60
;
t
+=
tm
->
tm_sec
;
return
t
;
}
configure.ac
View file @
903664b8
...
@@ -564,7 +564,7 @@ need_libc=false
...
@@ -564,7 +564,7 @@ need_libc=false
dnl Check for usual libc functions
dnl Check for usual libc functions
AC_CHECK_DECLS([nanosleep],,,[#include <time.h>])
AC_CHECK_DECLS([nanosleep],,,[#include <time.h>])
AC_CHECK_FUNCS([daemon fcntl fstatvfs fork getenv getpwuid_r isatty lstat memalign mkostemp mmap open_memstream openat pread posix_fadvise posix_madvise setlocale stricmp strnicmp strptime uselocale pthread_cond_timedwait_monotonic_np pthread_condattr_setclock])
AC_CHECK_FUNCS([daemon fcntl fstatvfs fork getenv getpwuid_r isatty lstat memalign mkostemp mmap open_memstream openat pread posix_fadvise posix_madvise setlocale stricmp strnicmp strptime uselocale pthread_cond_timedwait_monotonic_np pthread_condattr_setclock])
AC_REPLACE_FUNCS([atof atoll dirfd fdopendir ffsll flockfile fsync getdelim getpid lldiv nrand48 poll posix_memalign rewind setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tdestroy timespec_get strverscmp])
AC_REPLACE_FUNCS([atof atoll dirfd fdopendir ffsll flockfile fsync getdelim getpid lldiv nrand48 poll posix_memalign rewind setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tdestroy time
gm time
spec_get strverscmp])
AC_CHECK_FUNCS(fdatasync,,
AC_CHECK_FUNCS(fdatasync,,
[AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])
[AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])
])
])
...
...
include/vlc_fixups.h
View file @
903664b8
...
@@ -40,7 +40,8 @@
...
@@ -40,7 +40,8 @@
# endif
# endif
#endif
#endif
#if !defined (HAVE_GMTIME_R) || !defined (HAVE_LOCALTIME_R)
#if !defined (HAVE_GMTIME_R) || !defined (HAVE_LOCALTIME_R) \
|| !defined (HAVE_TIMEGM)
# include <time.h>
/* time_t */
# include <time.h>
/* time_t */
#endif
#endif
...
@@ -198,6 +199,10 @@ struct tm *gmtime_r (const time_t *, struct tm *);
...
@@ -198,6 +199,10 @@ struct tm *gmtime_r (const time_t *, struct tm *);
struct
tm
*
localtime_r
(
const
time_t
*
,
struct
tm
*
);
struct
tm
*
localtime_r
(
const
time_t
*
,
struct
tm
*
);
#endif
#endif
#ifndef HAVE_TIMEGM
time_t
timegm
(
const
struct
tm
*
);
#endif
#ifndef HAVE_TIMESPEC_GET
#ifndef HAVE_TIMESPEC_GET
#define TIME_UTC 1
#define TIME_UTC 1
struct
timespec
;
struct
timespec
;
...
...
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