mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-02 09:01:48 -05:00
Change error message handling
Change the handling of non-fatal errors. Now the non-fatal error messages are not shown in stderr and no assert() as default. The behavior can be changed with LIBASOUND_DEBUG environment variable.
This commit is contained in:
parent
73aa2549d9
commit
2b54677fdb
9 changed files with 462 additions and 165 deletions
31
src/error.c
31
src/error.c
|
|
@ -100,6 +100,10 @@ snd_lib_error_handler_t snd_lib_error = snd_lib_error_default;
|
|||
int snd_lib_error_set_handler(snd_lib_error_handler_t handler)
|
||||
{
|
||||
snd_lib_error = handler == NULL ? snd_lib_error_default : handler;
|
||||
#ifndef NDEBUG
|
||||
if (snd_lib_error != snd_lib_error_default)
|
||||
snd_err_msg = snd_lib_error;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -111,3 +115,30 @@ const char *snd_asoundlib_version(void)
|
|||
{
|
||||
return SND_LIB_VERSION_STR;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
/*
|
||||
* internal error handling
|
||||
*/
|
||||
static void snd_err_msg_default(const char *file, int line, const char *function, int err, const char *fmt, ...)
|
||||
{
|
||||
va_list arg;
|
||||
const char *verbose;
|
||||
|
||||
verbose = getenv("LIBASOUND_DEBUG");
|
||||
if (! verbose || ! *verbose)
|
||||
return;
|
||||
va_start(arg, fmt);
|
||||
fprintf(stderr, "ALSA lib %s:%i:(%s) ", file, line, function);
|
||||
vfprintf(stderr, fmt, arg);
|
||||
if (err)
|
||||
fprintf(stderr, ": %s", snd_strerror(err));
|
||||
putc('\n', stderr);
|
||||
va_end(arg);
|
||||
if (! strcmp(verbose, "assert"))
|
||||
assert(0);
|
||||
}
|
||||
|
||||
snd_lib_error_handler_t snd_err_msg = snd_err_msg_default;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue