afSetErrorHandler(3dm) afSetErrorHandler(3dm) NAME afSetErrorHandler - supply an alternate error reporting routine to the Audio File Library SYNOPSIS #include <dmedia/audiofile.h> AFerrfunc afSetErrorHandler(AFerrfunc efunc) PARAMETER efunc is a pointer to an error handling routine which is declared as: void errorfunc(long, const char*) RETURNED VALUE The returned value is a pointer to the previous error handling routine. DESCRIPTION afSetErrorHandler() allows you to override the default error handling routine. The arguments that are passed to the error handling routine are an error code and a string containing a description of the error. EXAMPLE #include <dmedia/audiofile.h> AFerrfunc defaultErrorHandler; void silentAFerror(long errnum, const char* fmt) { /* suppress AF errors here */ } ... /* supply a new error handler */ defaultErrorHandler = afSetErrorHandler(silentAFerror); /* AF errors won't be reported here */ ... /* restore the default error handler */ /* AF errors will be reported by the default error handler */ ... CAVEATS The AF library error handler function pointer is declared as a global variable, and therefor is not safe for use in multi-threaded applications. Specifically, a core dump may result if more than one thread attempts to use the error handler simultaneously. This can be avoided by calling afSetErrorHandler(NULL) to disable the feature entirely. The current version of the AF library has a MT-safe alternative to the AFerrorhandler: After disabling the internal error handler as shown above, an application should handle errors as in the example below: #include <dmedia/dmedia.h> AFfilehandle handle; handle = afOpenFile("some_filename", "r", NULL); /* attempt to open */ if(handle == NULL) { char detail[DM_MAX_ERROR_DETAIL]; /* storage for error detail */ int errorNumber; /* error token storage */ char *msg; /* short error message */ msg = dmGetError(&errorNumber, detail); if(msg != NULL) /* if NULL, no error was reported */ fprintf(stderr, "%s [error number %d]\n", detail, errorNumber); exit(1); /* or whatever */ } The application must add -ldmedia to its link list if it calls dmGetError(). See dmGetError(3dm) for more details on this alternative. SEE ALSO stdarg(5), afIntro(3dm), dmIntro(3dm), dmGetError(3dm) Page 2