void showTextFile(const char * filename) { #define MAX_TEXT_FILE_SIZE 65536 char *buf; int fd; int size; if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) { printf("\nFile not found: %s\n", filename); sleep(2); return; } size = file_size(fd); if (size > MAX_TEXT_FILE_SIZE) { size = MAX_TEXT_FILE_SIZE; } buf = malloc(size); read(fd, buf, size); close(fd); showTextBuffer(buf, size); free(buf); }
void showTextFile(const char * filename) { #define MAX_TEXT_FILE_SIZE 65536 char *buf; int fd; int size; if ((fd = open_bvdev("bt(0,0)", filename)) < 0) { printf("\nFile not found: %s\n", filename); sleep(2); return; } size = file_size(fd); if (size > MAX_TEXT_FILE_SIZE) { size = MAX_TEXT_FILE_SIZE; } buf = calloc(size,sizeof(char)); if (!buf) { printf("Couldn't allocate memory for the buf in showTextFile\n"); return ; } read(fd, buf, size); close(fd); showTextBuffer(buf, size); free(buf); }
static uint32_t load_keyboard_layout_file(const char *filename) { int fd; char magic[KEYBOARD_LAYOUTS_MAGIC_SIZE]; uint32_t version; if ((fd = open_bvdev("bt(0,0)", filename)) < 0) { goto fail; // fail } if (read(fd, magic, sizeof(magic)) != sizeof(magic)) { printf("Can't find magic in keyboard layout file: %s\n", filename); goto fail; } if (memcmp (magic, KEYBOARD_LAYOUTS_MAGIC, KEYBOARD_LAYOUTS_MAGIC_SIZE) != 0) { printf("Invalid magic code in keyboard layout file: %s\n", filename); goto fail; } if (read(fd, (char*) &version, sizeof(version)) != sizeof(version)) { printf("Can't get version of keyboard layout file: %s\n", filename); goto fail; } if (version != KEYBOARD_LAYOUTS_VERSION) { verbose("Bad version for keyboard layout file %s expected v%d found v%d\n", filename, KEYBOARD_LAYOUTS_VERSION, version); goto fail; } if (current_layout) free(current_layout); current_layout = malloc(sizeof(struct keyboard_layout)); if (!current_layout) goto fail; bzero(current_layout,sizeof(struct keyboard_layout)); key_b_lseek(fd, KEYBOARD_LAYOUTS_MAP_OFFSET, 0); if (read(fd, (char*) current_layout, sizeof(struct keyboard_layout)) != sizeof(struct keyboard_layout)) { printf("Wrong keyboard layout file %s size\n", filename); goto fail; } close(fd); return 1; fail: if (current_layout) { free(current_layout); current_layout = NULL; } return 0; }
/* loadConfigFile * * Returns 0 - successful. * -1 - unsuccesful. */ int loadConfigFile (const char *configFile, config_file_t *config) { int fd, count; if ((fd = open_bvdev("bt(0,0)", configFile, 0)) < 0) { return -1; } // read file count = read(fd, config->plist, IO_CONFIG_DATA_SIZE); close(fd); // build xml dictionary ParseXMLFile(config->plist, &config->dictionary); return 0; }