diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-07-08 04:34:11 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-07-08 04:34:11 +0200 |
commit | f982d006bb9e5ffb6bc032e62b5f34177a83df85 (patch) | |
tree | d0c88573dd27d0633675955165a64b036cc10974 /cmdutils.c | |
parent | 4cd066b69c08cd91aa4b5e40deb4b2f5c7e651ee (diff) | |
parent | 636ced8e1dc8248a1353b416240b93d70ad03edb (diff) | |
download | ffmpeg-f982d006bb9e5ffb6bc032e62b5f34177a83df85.tar.gz |
Merge commit '636ced8e1dc8248a1353b416240b93d70ad03edb'
* commit '636ced8e1dc8248a1353b416240b93d70ad03edb':
cmdutils: wrap exit explicitly
Conflicts:
avprobe.c
cmdutils.c
ffmpeg.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'cmdutils.c')
-rw-r--r-- | cmdutils.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/cmdutils.c b/cmdutils.c index 1fe0e56d29..b292763aef 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -111,6 +111,21 @@ static void log_callback_report(void *ptr, int level, const char *fmt, va_list v fflush(report_file); } +static void (*program_exit)(int ret); + +void register_exit(void (*cb)(int ret)) +{ + program_exit = cb; +} + +void exit_program(int ret) +{ + if (program_exit) + program_exit(ret); + + exit(ret); +} + double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max) { @@ -128,7 +143,7 @@ double parse_number_or_die(const char *context, const char *numstr, int type, else return d; av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max); - exit(1); + exit_program(1); return 0; } @@ -139,7 +154,7 @@ int64_t parse_time_or_die(const char *context, const char *timestr, if (av_parse_time(&us, timestr, is_duration) < 0) { av_log(NULL, AV_LOG_FATAL, "Invalid %s specification for %s: %s\n", is_duration ? "duration" : "date", context, timestr); - exit(1); + exit_program(1); } return us; } @@ -304,7 +319,7 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt, } } if (po->flags & OPT_EXIT) - exit(0); + exit_program(0); return 0; } @@ -364,7 +379,7 @@ void parse_options(void *optctx, int argc, char **argv, const OptionDef *options opt++; if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0) - exit(1); + exit_program(1); optindex += ret; } else { if (parse_arg_function) @@ -637,7 +652,7 @@ static void init_parse_context(OptionParseContext *octx, octx->nb_groups = nb_groups; octx->groups = av_mallocz(sizeof(*octx->groups) * octx->nb_groups); if (!octx->groups) - exit(1); + exit_program(1); for (i = 0; i < octx->nb_groups; i++) octx->groups[i].group_def = &groups[i]; @@ -817,7 +832,7 @@ int opt_loglevel(void *optctx, const char *opt, const char *arg) "Possible levels are numbers or:\n", arg); for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) av_log(NULL, AV_LOG_FATAL, "\"%s\"\n", log_levels[i].name); - exit(1); + exit_program(1); } av_log_set_level(level); return 0; @@ -1924,13 +1939,13 @@ void *grow_array(void *array, int elem_size, int *size, int new_size) { if (new_size >= INT_MAX / elem_size) { av_log(NULL, AV_LOG_ERROR, "Array too big.\n"); - exit(1); + exit_program(1); } if (*size < new_size) { uint8_t *tmp = av_realloc(array, new_size*elem_size); if (!tmp) { av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n"); - exit(1); + exit_program(1); } memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size); *size = new_size; |