[1/3] avutil: Add av_timegm as a public function

Message ID 1320704369-97079-1-git-send-email-martin@martin.st
State Committed
Headers show

Commit Message

Martin Storsjö Nov. 7, 2011, 10:19 p.m.
This is useful, since the normal timegm function isn't a standard
function (requiring _BSD_SOURCE or _SVID_SOURCE on glibc to
be visible, and not available on e.g. windows). The widely available
function mktime uses the local time zone, which requires ugly
workarounds to handle UTC time.
---
 doc/APIchanges         |    3 +++
 libavutil/avutil.h     |    2 +-
 libavutil/parseutils.c |    4 ++--
 libavutil/parseutils.h |    7 +++++++
 4 files changed, 13 insertions(+), 3 deletions(-)

Comments

Anton Khirnov Nov. 16, 2011, 9:04 a.m. | #1
On Tue,  8 Nov 2011 00:19:27 +0200, Martin Storsjö <martin@martin.st> wrote:
> This is useful, since the normal timegm function isn't a standard
> function (requiring _BSD_SOURCE or _SVID_SOURCE on glibc to
> be visible, and not available on e.g. windows). The widely available
> function mktime uses the local time zone, which requires ugly
> workarounds to handle UTC time.
> ---

Looks fine.

Patch

diff --git a/doc/APIchanges b/doc/APIchanges
index 5ef1fa5..5d2a2aa 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@  libavutil:   2011-04-18
 
 API changes, most recent first:
 
+2011-11-xx - xxxxxxx - lavu 51.15.0
+  Add av_timegm()
+
 2011-11-06 - ba04ecf - lavu 51.14.0
   Add av_strcasecmp() and av_strncasecmp() to avstring.h.
 
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 5ad7034..4b226e0 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -40,7 +40,7 @@ 
 #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
 
 #define LIBAVUTIL_VERSION_MAJOR 51
-#define LIBAVUTIL_VERSION_MINOR 14
+#define LIBAVUTIL_VERSION_MINOR 15
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
index c1647a0..a1d221b 100644
--- a/libavutil/parseutils.c
+++ b/libavutil/parseutils.c
@@ -461,7 +461,7 @@  static const char *small_strptime(const char *p, const char *fmt, struct tm *dt)
     }
 }
 
-static time_t mktimegm(struct tm *tm)
+time_t av_timegm(struct tm *tm)
 {
     time_t t;
 
@@ -582,7 +582,7 @@  int av_parse_time(int64_t *timeval, const char *timestr, int duration)
     } else {
         dt.tm_isdst = -1;       /* unknown */
         if (is_utc) {
-            t = mktimegm(&dt);
+            t = av_timegm(&dt);
         } else {
             t = mktime(&dt);
         }
diff --git a/libavutil/parseutils.h b/libavutil/parseutils.h
index 0d78b3e..cd913d8 100644
--- a/libavutil/parseutils.h
+++ b/libavutil/parseutils.h
@@ -19,6 +19,8 @@ 
 #ifndef AVUTIL_PARSEUTILS_H
 #define AVUTIL_PARSEUTILS_H
 
+#include <time.h>
+
 #include "rational.h"
 
 /**
@@ -114,4 +116,9 @@  int av_parse_time(int64_t *timeval, const char *timestr, int duration);
  */
 int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
 
+/**
+ * Convert the decomposed UTC time in tm to a time_t value.
+ */
+time_t av_timegm(struct tm *tm);
+
 #endif /* AVUTIL_PARSEUTILS_H */