You must provide both an open routine and a close routine for a native device driver. The current Mac OS does not require that these routines perform any specific tasks; however, the driver should keep track of open calls to match them with close calls. Open and close calls are always immediate.
Typical code for keeping track of kOpenCommand and kCloseCommand commands is shown in Listing 8-6.
Listing 8-6 Managing open and close commands
long gMyOpenCount;
OSErr DoOpenCommand (ParmBlkPtr thePb)
{
gMyOpenCount++;
return noErr;
}
OSErr DoCloseCommand (ParmBlkPtr thePb)
{
gMyOpenCount--;
return noErr;
}