alsa-lib/src/error.c

66 lines
1.9 KiB
C
Raw Normal View History

1998-08-13 15:42:56 +00:00
/*
* Error Routines
* Copyright (c) 1998 by Jaroslav Kysela <perex@suse.cz>
1998-08-13 15:42:56 +00:00
*
* snd_strerror routine needs to be recoded for locale support
*
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdio.h>
#include <stdlib.h>
2000-11-20 20:10:46 +00:00
#include <stdarg.h>
1998-08-13 15:42:56 +00:00
#include <string.h>
1998-08-30 21:08:44 +00:00
#include "asoundlib.h"
1998-08-13 15:42:56 +00:00
1998-11-27 14:57:39 +00:00
static const char *snd_error_codes[] =
{
1999-12-16 14:14:16 +00:00
"Sound protocol is not compatible"
1998-08-13 15:42:56 +00:00
};
1998-11-27 14:57:39 +00:00
const char *snd_strerror(int errnum)
1998-08-13 15:42:56 +00:00
{
1998-11-27 14:57:39 +00:00
if (errnum < 0)
errnum = -errnum;
if (errnum < SND_ERROR_BEGIN)
return (const char *) strerror(errnum);
errnum -= SND_ERROR_BEGIN;
2000-05-08 18:53:38 +00:00
if ((unsigned int) errnum >= sizeof(snd_error_codes) / sizeof(const char *))
1998-11-27 14:57:39 +00:00
return "Unknown error";
return snd_error_codes[errnum];
1998-08-13 15:42:56 +00:00
}
2000-11-20 20:10:46 +00:00
2000-11-25 16:36:18 +00:00
static void snd_lib_error_default(const char *file, int line, const char *function, int err, const char *fmt, ...)
2000-11-20 20:10:46 +00:00
{
va_list arg;
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);
}
2000-11-25 16:36:18 +00:00
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;
return 0;
}