Skip to content

Commit 27f2746

Browse files
committed
parseutils: Make av_small_strptime public
And use it in libavformat. Based on a similar patch by Stefano Sabatini <[email protected]>.
1 parent 108f2f3 commit 27f2746

File tree

6 files changed

+42
-17
lines changed

6 files changed

+42
-17
lines changed

configure

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,6 @@ SYSTEM_FUNCS="
14871487
setrlimit
14881488
Sleep
14891489
strerror_r
1490-
strptime
14911490
sysconf
14921491
sysctl
14931492
usleep
@@ -4133,7 +4132,6 @@ check_func_headers time.h nanosleep || { check_func_headers time.h nanosleep -lr
41334132
check_func sched_getaffinity
41344133
check_func setrlimit
41354134
check_func strerror_r
4136-
check_func strptime
41374135
check_func sysconf
41384136
check_func sysctl
41394137
check_func usleep

doc/APIchanges

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ libavutil: 2014-08-09
1313

1414
API changes, most recent first:
1515

16+
2015-xx-xx - xxxxxxx - lavu 54.11.0
17+
Add av_small_strptime().
18+
1619
2015-xx-xx - xxxxxxx - lavc 56.22.0
1720
Add FF_PROFILE_DTS_EXPRESS.
1821

libavformat/utils.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,21 +2902,14 @@ int ff_find_stream_index(AVFormatContext *s, int id)
29022902

29032903
int64_t ff_iso8601_to_unix_time(const char *datestr)
29042904
{
2905-
#if HAVE_STRPTIME
29062905
struct tm time1 = { 0 }, time2 = { 0 };
29072906
char *ret1, *ret2;
2908-
ret1 = strptime(datestr, "%Y - %m - %d %T", &time1);
2909-
ret2 = strptime(datestr, "%Y - %m - %dT%T", &time2);
2907+
ret1 = av_small_strptime(datestr, "%Y - %m - %d %T", &time1);
2908+
ret2 = av_small_strptime(datestr, "%Y - %m - %dT%T", &time2);
29102909
if (ret2 && !ret1)
29112910
return av_timegm(&time2);
29122911
else
29132912
return av_timegm(&time1);
2914-
#else
2915-
av_log(NULL, AV_LOG_WARNING,
2916-
"strptime() unavailable on this system, cannot convert "
2917-
"the date string.\n");
2918-
return 0;
2919-
#endif
29202913
}
29212914

29222915
int avformat_query_codec(const AVOutputFormat *ofmt, enum AVCodecID codec_id,

libavutil/parseutils.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ static int date_get_num(const char **pp,
400400
return val;
401401
}
402402

403-
static const char *small_strptime(const char *p, const char *fmt, struct tm *dt)
403+
const char *av_small_strptime(const char *p, const char *fmt, struct tm *dt)
404404
{
405405
int c, val;
406406

@@ -453,7 +453,7 @@ static const char *small_strptime(const char *p, const char *fmt, struct tm *dt)
453453
dt->tm_mday = val;
454454
break;
455455
case 'T':
456-
p = small_strptime(p, "%H:%M:%S", dt);
456+
p = av_small_strptime(p, "%H:%M:%S", dt);
457457
if (!p)
458458
return NULL;
459459
break;
@@ -526,7 +526,7 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
526526

527527
/* parse the year-month-day part */
528528
for (i = 0; i < FF_ARRAY_ELEMS(date_fmt); i++) {
529-
q = small_strptime(p, date_fmt[i], &dt);
529+
q = av_small_strptime(p, date_fmt[i], &dt);
530530
if (q) {
531531
break;
532532
}
@@ -550,7 +550,7 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
550550

551551
/* parse the hour-minute-second part */
552552
for (i = 0; i < FF_ARRAY_ELEMS(time_fmt); i++) {
553-
q = small_strptime(p, time_fmt[i], &dt);
553+
q = av_small_strptime(p, time_fmt[i], &dt);
554554
if (q) {
555555
break;
556556
}
@@ -562,7 +562,7 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
562562
++p;
563563
}
564564
/* parse timestr as HH:MM:SS */
565-
q = small_strptime(p, time_fmt[0], &dt);
565+
q = av_small_strptime(p, time_fmt[0], &dt);
566566
if (!q) {
567567
char *o;
568568
/* parse timestr as S+ */

libavutil/parseutils.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,37 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration);
116116
*/
117117
int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
118118

119+
/**
120+
* Simplified version of strptime
121+
*
122+
* Parse the input string p according to the format string fmt and
123+
* store its results in the structure dt.
124+
*
125+
* Neither text and locale's alternative representation are supported.
126+
*
127+
* The supported input field descriptors are listed below.
128+
* - %H: the hour as a decimal number, using a 24-hour clock, in the
129+
* range '00' through '23'
130+
* - %M: the minute as a decimal number, using a 24-hour clock, in the
131+
* range '00' through '59'
132+
* - %S: the second as a decimal number, using a 24-hour clock, in the
133+
* range '00' through '59'
134+
* - %Y: the year as a decimal number, using the Gregorian calendar
135+
* - %m: the month as a decimal number, in the range '1' through '12'
136+
* - %d: the day of the month as a decimal number, in the range '1'
137+
* through '31'
138+
* - %T: alias for '%H:%M:%S'
139+
* - %%: a literal '%'
140+
*
141+
* @return a pointer to the first character not processed in this function
142+
* call. In case the input string contains more characters than
143+
* required by the format string the return value points right after
144+
* the last consumed input character. In case the whole input string
145+
* is consumed the return value points to the null byte at the end of
146+
* the string. On failure NULL is returned.
147+
*/
148+
const char *av_small_strptime(const char *p, const char *fmt, struct tm *dt);
149+
119150
/**
120151
* Convert the decomposed UTC time in tm to a time_t value.
121152
*/

libavutil/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
*/
5555

5656
#define LIBAVUTIL_VERSION_MAJOR 54
57-
#define LIBAVUTIL_VERSION_MINOR 10
57+
#define LIBAVUTIL_VERSION_MINOR 11
5858
#define LIBAVUTIL_VERSION_MICRO 0
5959

6060
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

0 commit comments

Comments
 (0)