static int openKeyboardDevice (BrailleDisplay *brl) { static const char deviceName[] = KEYBOARD_DEVICE_NAME; char *devicePath = findKeyboardDevice(deviceName); if (devicePath) { int deviceDescriptor = open(devicePath, O_RDONLY); if (deviceDescriptor != -1) { if (setBlockingIo(deviceDescriptor, 0)) { if (ioctl(deviceDescriptor, EVIOCGRAB, 1) != -1) { logMessage(LOG_DEBUG, "Keyboard Device Opened: %s: %s: fd=%d", deviceName, devicePath, deviceDescriptor); free(devicePath); brl->data->keyboardDevice = deviceDescriptor; return 1; } else { logSystemError("ioctl[EVIOCGRAB]"); } } close(deviceDescriptor); } else { logMessage(LOG_DEBUG, "keyboard device open error: %s: %s", devicePath, strerror(errno)); } free(devicePath); } return 0; }
PcmDevice * openPcmDevice (int errorLevel, const char *device) { PcmDevice *pcm; if ((pcm = malloc(sizeof(*pcm)))) { if (!*device) device = PCM_OSS_DEVICE_PATH; if ((pcm->fileDescriptor = open(device, O_WRONLY|O_NONBLOCK)) != -1) { /* Nonblocking if snd_seq_oss is loaded with nonblock_open=1. * There appears to be a bug in this case as write() always * returns the full count even though large chunks of sound are * missing. For now, therefore, force blocking output. */ setBlockingIo(pcm->fileDescriptor, 1); pcm->driverVersion = 0X030000; #ifdef OSS_GETVERSION if (ioctl(pcm->fileDescriptor, OSS_GETVERSION, &pcm->driverVersion) == -1) logMessage(errorLevel, "cannot get OSS driver version"); #endif /* OSS_GETVERSION */ logMessage(LOG_DEBUG, "OPSS driver version: %06X", pcm->driverVersion); setPcmSampleRate(pcm, 8000); setPcmChannelCount(pcm, 1); return pcm; } else { logMessage(errorLevel, "cannot open PCM device: %s: %s", device, strerror(errno)); } free(pcm); } else { logSystemError("PCM device allocation"); } return NULL; }
int usbMakeInputPipe (UsbEndpoint *endpoint) { if (usbHaveInputPipe(endpoint)) return 1; if (createAnonymousPipe(&endpoint->direction.input.pipe.input, &endpoint->direction.input.pipe.output)) { if (setBlockingIo(endpoint->direction.input.pipe.output, 0)) { return 1; } } usbDestroyInputPipe(endpoint); return 0; }