Specifications

D
evice Driver Programming
17-18
functions. The order in which the functions are executed is the reverse of the order in
which they are registered with a call to atexit.
You might want to use the atexit routine to ensure that a call is made to the driver
routine that is responsible for cleaning up opened devices and freeing all allocated
resources. If a user program that opens a device controlled by the user-level driver aborts,
the driver’s close routine is never called; other processes’ attempts to open the device
fail. It is recommended that atexit be invoked on the first call to the driver’s open
routine (see “The open Routine” on page 17-23 for an explanation of the procedures for
developing this routine) or on a call to a driver initialization routine.
The specifications required for using the atexit routine are as follows:
int atexit(function)
void (*function)();
The argument is defined as follows:
function a pointer to a function returning type void
If no errors occur, the atexit routine returns a value of 0; otherwise, it returns a value of
-1. For reference information on this routine, refer to the atexit(3C) system manual
page.
The uderror(3X) Library Routine 17
The uderror routine enables you to write a message describing an error code returned
by a user-level device driver routine to the standard error. It can be used by a user-level
driver or by an application program that is using a user-level driver.
The specifications required for using the uderror routine are as follows:
#include <userdriv.h>
void uderror(error
,
s)
int error;
char *s;
extern char *ud_errmsg[];
extern int udmaxerr;
The arguments are defined as follows:
error a user-level device driver error code that has been returned by a user-level
driver routine. Codes that can be returned are defined in the file
<userdriv.h>.
s a pointer to a descriptive character string that is to be written to the standard
error along with the error message corresponding to the specified error code. It