fftools/cmdutils: Add function to report error before exit

This is designed to improve and unify error handling for
allocation failures for the many (often small) allocations that we have
in the fftools. These typically either don't return an error message
or an error message that is not really helpful to the user
and can be replaced by a generic error message without loss of
information.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2022-08-27 14:52:13 +02:00
parent 319e8a49b5
commit e157b21a90
2 changed files with 17 additions and 0 deletions

View File

@ -90,6 +90,12 @@ void register_exit(void (*cb)(int ret))
program_exit = cb; program_exit = cb;
} }
void report_and_exit(int ret)
{
av_log(NULL, AV_LOG_FATAL, "%s\n", av_err2str(ret));
exit_program(AVUNERROR(ret));
}
void exit_program(int ret) void exit_program(int ret)
{ {
if (program_exit) if (program_exit)

View File

@ -54,6 +54,17 @@ extern int hide_banner;
*/ */
void register_exit(void (*cb)(int ret)); void register_exit(void (*cb)(int ret));
/**
* Reports an error corresponding to the provided
* AVERROR code and calls exit_program() with the
* corresponding POSIX error code.
* @note ret must be an AVERROR-value of a POSIX error code
* (i.e. AVERROR(EFOO) and not AVERROR_FOO).
* library functions can return both, so call this only
* with AVERROR(EFOO) of your own.
*/
void report_and_exit(int ret) av_noreturn;
/** /**
* Wraps exit with a program-specific cleanup routine. * Wraps exit with a program-specific cleanup routine.
*/ */