1 | /* |
---|
2 | Audio File Library |
---|
3 | Copyright (C) 1998, Michael Pruett <michael@68k.org> |
---|
4 | |
---|
5 | This library is free software; you can redistribute it and/or |
---|
6 | modify it under the terms of the GNU Library General Public |
---|
7 | License as published by the Free Software Foundation; either |
---|
8 | version 2 of the License, or (at your option) any later version. |
---|
9 | |
---|
10 | This library is distributed in the hope that it will be useful, |
---|
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
13 | Library General Public License for more details. |
---|
14 | |
---|
15 | You should have received a copy of the GNU Library General Public |
---|
16 | License along with this library; if not, write to the |
---|
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
18 | Boston, MA 02111-1307 USA. |
---|
19 | */ |
---|
20 | |
---|
21 | /* |
---|
22 | error.c |
---|
23 | |
---|
24 | This file contains the routines used in the Audio File Library's |
---|
25 | error handling. |
---|
26 | */ |
---|
27 | |
---|
28 | #ifdef HAVE_CONFIG_H |
---|
29 | #include <config.h> |
---|
30 | #endif |
---|
31 | |
---|
32 | #include <stdio.h> |
---|
33 | #include <stdarg.h> |
---|
34 | #include <assert.h> |
---|
35 | #include "audiofile.h" |
---|
36 | |
---|
37 | static void defaultErrorFunction (long error, const char *str); |
---|
38 | |
---|
39 | AFerrfunc errorFunction = defaultErrorFunction; |
---|
40 | |
---|
41 | AFerrfunc afSetErrorHandler (AFerrfunc efunc) |
---|
42 | { |
---|
43 | AFerrfunc old; |
---|
44 | |
---|
45 | old = errorFunction; |
---|
46 | errorFunction = efunc; |
---|
47 | |
---|
48 | return old; |
---|
49 | } |
---|
50 | |
---|
51 | static void defaultErrorFunction (long error, const char *str) |
---|
52 | { |
---|
53 | fprintf(stderr, "Audio File Library: "); |
---|
54 | fprintf(stderr, "%s", str); |
---|
55 | fprintf(stderr, " [error %ld]\n", error); |
---|
56 | } |
---|
57 | |
---|
58 | void _af_error (int errorCode, const char *fmt, ...) |
---|
59 | { |
---|
60 | char buf[1024]; |
---|
61 | va_list ap; |
---|
62 | |
---|
63 | va_start(ap, fmt); |
---|
64 | |
---|
65 | vsnprintf(buf, 1024, fmt, ap); |
---|
66 | |
---|
67 | va_end(ap); |
---|
68 | |
---|
69 | if (errorFunction != NULL) |
---|
70 | errorFunction(errorCode, buf); |
---|
71 | } |
---|