* misc parsing utilities
*/
-#include <sys/time.h>
#include <time.h>
#include "avstring.h"
#include "avutil.h"
+#include "common.h"
#include "eval.h"
#include "log.h"
#include "random_seed.h"
}
}
if (i == n) {
- p = str;
- width = strtol(p, &p, 10);
+ width = strtol(str, &p, 10);
if (*p)
p++;
height = strtol(p, &p, 10);
}
if (tail) {
- unsigned long int alpha;
+ double alpha;
const char *alpha_string = tail;
if (!strncmp(alpha_string, "0x", 2)) {
alpha = strtoul(alpha_string, &tail, 16);
alpha = 255 * strtod(alpha_string, &tail);
}
- if (tail == alpha_string || *tail || alpha > 255) {
+ if (tail == alpha_string || *tail || alpha > 255 || alpha < 0) {
av_log(log_ctx, AV_LOG_ERROR, "Invalid alpha value specifier '%s' in '%s'\n",
alpha_string, color_string);
return AVERROR(EINVAL);
}
}
-static time_t mktimegm(struct tm *tm)
+time_t av_timegm(struct tm *tm)
{
time_t t;
{
const char *p;
int64_t t;
- struct tm dt;
+ struct tm dt = { 0 };
int i;
static const char * const date_fmt[] = {
"%Y-%m-%d",
char lastch;
int negative = 0;
-#undef time
time_t now = time(0);
len = strlen(timestr);
lastch = '\0';
is_utc = (lastch == 'z' || lastch == 'Z');
- memset(&dt, 0, sizeof(dt));
-
p = timestr;
q = NULL;
if (!duration) {
} else {
dt.tm_isdst = -1; /* unknown */
if (is_utc) {
- t = mktimegm(&dt);
+ t = av_timegm(&dt);
} else {
t = mktime(&dt);
}
#ifdef TEST
-#undef printf
-
int main(void)
{
printf("Testing av_parse_video_rate()\n");
{
int i;
- const char *rates[] = {
+ static const char *const rates[] = {
"-inf",
"inf",
"nan",
for (i = 0; i < FF_ARRAY_ELEMS(rates); i++) {
int ret;
- AVRational q = (AVRational){0, 0};
- ret = av_parse_video_rate(&q, rates[i]),
- printf("'%s' -> %d/%d ret:%d\n",
- rates[i], q.num, q.den, ret);
+ AVRational q = { 0, 0 };
+ ret = av_parse_video_rate(&q, rates[i]);
+ printf("'%s' -> %d/%d %s\n",
+ rates[i], q.num, q.den, ret ? "ERROR" : "OK");
}
}
{
int i;
uint8_t rgba[4];
- const char *color_names[] = {
- "bikeshed",
- "RaNdOm",
+ static const char *const color_names[] = {
"foo",
"red",
"Red ",
for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) {
if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0)
- printf("%s -> R(%d) G(%d) B(%d) A(%d)\n", color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]);
+ printf("%s -> R(%d) G(%d) B(%d) A(%d)\n",
+ color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]);
}
}