static UinputObject * newUinputInstance (const char *device) { char name[0X40]; snprintf(name, sizeof(name), "Keyboard Instance - %s", locatePathName(device)); return newUinputObject(name); }
void beginProgram (int argumentCount, char **argumentVector) { #if defined(GRUB_RUNTIME) #else /* at exit */ atexit(endProgram); #endif /* at exit */ initializeSystemObject(); prepareLocale(); if ((programPath = getProgramPath())) { registerProgramMemory("program-path", &programPath); } else { programPath = argumentVector[0]; } if (!isExplicitPath(programPath)) { char *path = findProgram(programPath); if (!path) path = testProgram(".", programPath); if (path) programPath = path; } if (isExplicitPath(programPath)) { #if defined(HAVE_REALPATH) && defined(PATH_MAX) if (!isAbsolutePath(programPath)) { char buffer[PATH_MAX]; char *path = realpath(programPath, buffer); if (path) { char *realPath = strdup(path); if (realPath) { programPath = realPath; } else { logMallocError(); } } else { logSystemError("realpath"); } } #endif /* defined(HAVE_REALPATH) && defined(PATH_MAX) */ if (!isAbsolutePath(programPath)) { char *directory; if ((directory = getWorkingDirectory())) { char *path; if ((path = makePath(directory, programPath))) programPath = path; free(directory); } } } programName = locatePathName(programPath); pushLogPrefix(programName); }
static int monitorKeyboard (KeyboardInstanceObject *kio) { const char *deviceName = locatePathName(kio->kix->device.path); if ((kio->kix->file.descriptor = open(kio->kix->device.path, O_RDONLY)) != -1) { struct stat status; if (fstat(kio->kix->file.descriptor, &status) != -1) { if (S_ISCHR(status.st_mode)) { { char description[0X100]; STR_BEGIN(description, sizeof(description)); STR_PRINTF("%s:", deviceName); { struct input_id identity; if (ioctl(kio->kix->file.descriptor, EVIOCGID, &identity) != -1) { STR_PRINTF(" bus=%04X vnd=%04X prd=%04X ver=%04X", identity.bustype, identity.vendor, identity.product, identity.version); { static const KeyboardType typeTable[] = { #ifdef BUS_I8042 [BUS_I8042] = KBD_TYPE_PS2, #endif /* BUS_I8042 */ #ifdef BUS_USB [BUS_USB] = KBD_TYPE_USB, #endif /* BUS_USB */ #ifdef BUS_BLUETOOTH [BUS_BLUETOOTH] = KBD_TYPE_Bluetooth, #endif /* BUS_BLUETOOTH */ }; if (identity.bustype < ARRAY_COUNT(typeTable)) { kio->actualProperties.type = typeTable[identity.bustype]; } } kio->actualProperties.vendor = identity.vendor; kio->actualProperties.product = identity.product; } else if (errno != ENOTTY) { logMessage(LOG_WARNING, "cannot get input device identity: %s: %s", deviceName, strerror(errno)); } }
FILE * openDataFile (const char *path, const char *mode, int optional) { const char *name = locatePathName(path); const char *overrideDirectory = getOverrideDirectory(); char *overridePath; FILE *file; if (!overrideDirectory) { overridePath = NULL; } else if ((overridePath = makePath(overrideDirectory, name))) { if (testFilePath(overridePath)) { file = openFile(overridePath, mode, optional); goto done; } } if (!(file = openFile(path, mode, optional))) { if ((*mode == 'w') || (*mode == 'a')) { if (errno == ENOENT) { char *directory = getPathDirectory(path); if (directory) { int exists = ensureDirectory(directory); free(directory); if (exists) { file = openFile(path, mode, optional); goto done; } } } if (((errno == EACCES) || (errno == EROFS)) && overridePath) { if (ensureDirectory(overrideDirectory)) { file = openFile(overridePath, mode, optional); goto done; } } } } done: if (overridePath) free(overridePath); return file; }
int main (int argc, char *argv[]) { ProgramExitStatus exitStatus = PROG_EXIT_SUCCESS; { static const OptionsDescriptor descriptor = { OPTION_TABLE(programOptions), .applicationName = "ktbtest", .argumentsSummary = "key-table" }; PROCESS_OPTIONS(descriptor, argc, argv); } { char **const paths[] = { &opt_driversDirectory, &opt_tablesDirectory, NULL }; fixInstallPaths(paths); } if (argc) { const char *keyTableName = (argc--, *argv++); char *keyTablePath = makeKeyTablePath(opt_tablesDirectory, keyTableName); if (keyTablePath) { KEY_NAME_TABLES_REFERENCE keyNameTables; { const char *file = locatePathName(keyTablePath); size_t length = strrchr(file, '.') - file; char name[length + 1]; memcpy(name, file, length); name[length] = 0; keyNameTables = getKeyNameTables(name); } if (keyNameTables) { if (opt_listKeyNames) if (!listKeyNames(keyNameTables, listLine, NULL)) exitStatus = PROG_EXIT_FATAL; if (exitStatus == PROG_EXIT_SUCCESS) { KeyTable *keyTable = compileKeyTable(keyTablePath, keyNameTables); if (keyTable) { if (opt_listKeyTable) if (!listKeyTable(keyTable, listLine, NULL)) exitStatus = PROG_EXIT_FATAL; destroyKeyTable(keyTable); } else { exitStatus = PROG_EXIT_FATAL; } } } else { exitStatus = PROG_EXIT_FATAL; } free(keyTablePath); } else { exitStatus = PROG_EXIT_FATAL; } } else { logMessage(LOG_ERR, "missing key table name"); exitStatus = PROG_EXIT_SYNTAX; } return exitStatus; }
int isExplicitPath (const char *path) { return locatePathName(path) != path; }
const char * locatePathExtension (const char *path) { const char *name = locatePathName(path); return strrchr(name, '.'); }
int main (int argc, char *argv[]) { ProgramExitStatus exitStatus = PROG_EXIT_SUCCESS; { static const OptionsDescriptor descriptor = { OPTION_TABLE(programOptions), .applicationName = "brltty-ktb", .argumentsSummary = "key-table" }; PROCESS_OPTIONS(descriptor, argc, argv); } driverObject = NULL; if (argc) { const char *tableName = (argc--, *argv++); KeyTableDescriptor ktd; int gotKeyTableDescriptor; { const char *file = locatePathName(tableName); const char *delimiter = strrchr(file, '.'); size_t length = delimiter? (delimiter - file): strlen(file); char name[length + 1]; memcpy(name, file, length); name[length] = 0; gotKeyTableDescriptor = getKeyTableDescriptor(&ktd, name); } if (gotKeyTableDescriptor) { if (opt_listKeyNames) { if (!listKeyNames(ktd.names, hlpWriteLine, NULL)) { exitStatus = PROG_EXIT_FATAL; } } if (exitStatus == PROG_EXIT_SUCCESS) { KeyTable *keyTable = compileKeyTable(ktd.path, ktd.names); if (keyTable) { if (opt_audit) { if (!auditKeyTable(keyTable, ktd.path)) { exitStatus = PROG_EXIT_FATAL; } } if (opt_listHelpScreen) { if (!listKeyTable(keyTable, NULL, hlpWriteLine, NULL)) { exitStatus = PROG_EXIT_FATAL; } } if (opt_listRestructuredText) { RestructuredTextData rst = { .headerLevel = 0, .elementLevel = 0, .elementBullet = WC_C(' '), .blankLine = 0 }; if (!listKeyTable(keyTable, &rstMethods, rstWriteLine, &rst)) { exitStatus = PROG_EXIT_FATAL; } } destroyKeyTable(keyTable); } else { exitStatus = PROG_EXIT_FATAL; } } free(ktd.path); } else {
int openCharacterDevice (const char *name, int flags, int major, int minor) { char *path = getDevicePath(name); int descriptor; if (!path) { descriptor = -1; } else if ((descriptor = open(path, flags)) != -1) { logMessage(LOG_DEBUG, "device opened: %s: fd=%d", path, descriptor); } else { logMessage(LOG_DEBUG, "cannot open device: %s: %s", path, strerror(errno)); if (errno == ENOENT) { free(path); if ((path = makeWritablePath(locatePathName(name)))) { if ((descriptor = open(path, flags)) != -1) { logMessage(LOG_DEBUG, "device opened: %s: fd=%d", path, descriptor); } else { logMessage(LOG_DEBUG, "cannot open device: %s: %s", path, strerror(errno)); if (errno == ENOENT) { mode_t mode = S_IFCHR | S_IRUSR | S_IWUSR; if (mknod(path, mode, makedev(major, minor)) == -1) { logMessage(LOG_DEBUG, "cannot create device: %s: %s", path, strerror(errno)); } else { logMessage(LOG_DEBUG, "device created: %s mode=%06o major=%d minor=%d", path, mode, major, minor); if ((descriptor = open(path, flags)) != -1) { logMessage(LOG_DEBUG, "device opened: %s: fd=%d", path, descriptor); } else { logMessage(LOG_DEBUG, "cannot open device: %s: %s", path, strerror(errno)); } } } } } } } if (descriptor != -1) { int ok = 0; struct stat status; if (fstat(descriptor, &status) == -1) { logMessage(LOG_DEBUG, "cannot fstat device: %d [%s]: %s", descriptor, path, strerror(errno)); } else if (!S_ISCHR(status.st_mode)) { logMessage(LOG_DEBUG, "not a character device: %s: fd=%d", path, descriptor); } else { ok = 1; } if (!ok) { close(descriptor); logMessage(LOG_DEBUG, "device closed: %s: fd=%d", path, descriptor); descriptor = -1; } } if (path) free(path); return descriptor; }