int cw_device_open(void) { static int atexitinitialized = 0; unsigned int i; if (atexitinitialized) { cw_device_close(); } gSIDs = 0; gSwapSIDs = FALSE; for (i = 0; i < 2; i++) { if ((gDiskPort[i] = CreatePort(NULL, 0)) != NULL) { if (gCatweaselReq[i] = (struct IOExtTD *)CreateExtIO(gDiskPort[i], sizeof(struct IOExtTD))) { if (OpenDevice("catweaselsid.device", i, (struct IORequest *)gCatweaselReq[i], 0)) { DeleteExtIO((struct IORequest *)gCatweaselReq[i]); DeletePort(gDiskPort[i]); gCatweaselReq[i] = NULL; gDiskPort[i] = NULL; } else { gSIDs++; } } } } if (gSIDs == 0) { return -1; } if (gCatweaselReq[1] && gCatweaselReq[0] == NULL) { gSwapSIDs = TRUE; } /* install exit handler, so device is closed on exit */ if (!atexitinitialized) { atexitinitialized = 1; atexit((voidfunc_t)cw_device_close); } sidfh = 1; /* ok */ return 1; }
int catweaselmkiii_drv_close(void) { #ifdef HAVE_CWSID_H if (use_cw_device) { cw_device_close(); use_cw_device = 0; } #endif #ifdef HAVE_CATWEASELMKIII_IO if (use_cw_pci) { cw_pci_close(); use_cw_pci = 0; } #endif return 0; }