[FFmpeg-devel] [PATCH] lavu: add av_small_strptime() in parseutils.h
Stefano Sabatini
stefasab at gmail.com
Sat Sep 1 13:34:19 CEST 2012
Allow to avoid a dependency on strptime() on systems which do not support
it.
In particular, fix trac ticket #992.
---
configure | 2 --
doc/APIchanges | 6 ++++++
libavformat/utils.c | 10 ++--------
libavutil/parseutils.c | 18 ++++--------------
libavutil/parseutils.h | 19 +++++++++++++++++++
5 files changed, 31 insertions(+), 24 deletions(-)
diff --git a/configure b/configure
index 576ada7b..b097d87 100755
--- a/configure
+++ b/configure
@@ -1359,7 +1359,6 @@ HAVE_LIST="
socklen_t
soundcard_h
strerror_r
- strptime
struct_addrinfo
struct_group_source_req
struct_ip_mreq_source
@@ -3422,7 +3421,6 @@ check_func_headers malloc.h _aligned_malloc && enable aligned_malloc
check_func setrlimit
check_func snprintf
check_func strerror_r
-check_func strptime
check_func sched_getaffinity
check_func sysconf
check_func sysctl
diff --git a/doc/APIchanges b/doc/APIchanges
index f9a624e..ef412ae 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,12 @@ libavutil: 2011-04-18
API changes, most recent first:
+2012-09-01 - xxxxxxx - lavu 51.70.100 - parseutils.h
+ Add av_small_strptime() time parsing function.
+
+ Can be used as a stripped-down replacement for strptime(), on
+ systems which do not support it.
+
2012-08-13 - xxxxxxx - lavfi 3.8.100 - avfilter.h
Add avfilter_get_class() function, and priv_class field to AVFilter
struct.
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 4ce0a0c..d87bee0 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4484,20 +4484,14 @@ void ff_make_absolute_url(char *buf, int size, const char *base,
int64_t ff_iso8601_to_unix_time(const char *datestr)
{
-#if HAVE_STRPTIME
struct tm time1 = {0}, time2 = {0};
char *ret1, *ret2;
- ret1 = strptime(datestr, "%Y - %m - %d %T", &time1);
- ret2 = strptime(datestr, "%Y - %m - %dT%T", &time2);
+ ret1 = av_small_strptime(datestr, "%Y - %m - %d %H:%M:%s", &time1);
+ ret2 = av_small_strptime(datestr, "%Y - %m - %dT%H:%M:%s", &time2);
if (ret2 && !ret1)
return av_timegm(&time2);
else
return av_timegm(&time1);
-#else
- av_log(NULL, AV_LOG_WARNING, "strptime() unavailable on this system, cannot convert "
- "the date string.\n");
- return 0;
-#endif
}
int avformat_query_codec(AVOutputFormat *ofmt, enum AVCodecID codec_id, int std_compliance)
diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
index 5884411..42508b0 100644
--- a/libavutil/parseutils.c
+++ b/libavutil/parseutils.c
@@ -438,17 +438,7 @@ static int date_get_num(const char **pp,
return val;
}
-/**
- * Parse the input string p according to the format string fmt and
- * store its results in the structure dt.
- * This implementation supports only a subset of the formats supported
- * by the standard strptime().
- *
- * @return a pointer to the first character not processed in this
- * function call, or NULL in case the function fails to match all of
- * the fmt string and therefore an error occurred
- */
-static const char *small_strptime(const char *p, const char *fmt, struct tm *dt)
+const char *av_small_strptime(const char *p, const char *fmt, struct tm *dt)
{
int c, val;
@@ -558,7 +548,7 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
/* parse the year-month-day part */
for (i = 0; i < FF_ARRAY_ELEMS(date_fmt); i++) {
- q = small_strptime(p, date_fmt[i], &dt);
+ q = av_small_strptime(p, date_fmt[i], &dt);
if (q)
break;
}
@@ -576,7 +566,7 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
/* parse the hour-minute-second part */
for (i = 0; i < FF_ARRAY_ELEMS(time_fmt); i++) {
- q = small_strptime(p, time_fmt[i], &dt);
+ q = av_small_strptime(p, time_fmt[i], &dt);
if (q)
break;
}
@@ -587,7 +577,7 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
++p;
}
/* parse timestr as HH:MM:SS */
- q = small_strptime(p, time_fmt[0], &dt);
+ q = av_small_strptime(p, time_fmt[0], &dt);
if (!q) {
/* parse timestr as S+ */
dt.tm_sec = strtol(p, (void *)&q, 10);
diff --git a/libavutil/parseutils.h b/libavutil/parseutils.h
index 7c7a91f..fc49ca9 100644
--- a/libavutil/parseutils.h
+++ b/libavutil/parseutils.h
@@ -133,6 +133,25 @@ int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen,
int av_parse_time(int64_t *timeval, const char *timestr, int duration);
/**
+ * Parse the input string p according to the format string fmt and
+ * store its results in the structure dt.
+ * This implementation supports only a subset of the formats supported
+ * by the standard strptime().
+ * In particular it only supports the parameters:
+ * - H
+ * - M
+ * - S
+ * - Y
+ * - m
+ * - d
+ *
+ * @return a pointer to the first character not processed in this
+ * function call, or NULL in case the function fails to match all of
+ * the fmt string and therefore an error occurred
+ */
+const char *av_small_strptime(const char *p, const char *fmt, struct tm *dt);
+
+/**
* Attempt to find a specific tag in a URL.
*
* syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
--
1.7.5.4
More information about the ffmpeg-devel
mailing list