static bool intfstream_file_get_serial(const char *name, uint64_t offset, uint64_t size, char *serial) { int rv; uint8_t *data = NULL; int64_t file_size = -1; intfstream_t *fd = intfstream_open_file(name, RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE); if (!fd) return 0; if (intfstream_seek(fd, 0, SEEK_END) == -1) goto error; file_size = intfstream_tell(fd); if (intfstream_seek(fd, 0, SEEK_SET) == -1) goto error; if (file_size < 0) goto error; if (offset != 0 || size < (uint64_t) file_size) { if (intfstream_seek(fd, (int64_t)offset, SEEK_SET) == -1) goto error; data = (uint8_t*)malloc((size_t)size); if (intfstream_read(fd, data, size) != (int64_t) size) { free(data); goto error; } intfstream_close(fd); free(fd); fd = intfstream_open_memory(data, RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE, size); if (!fd) { free(data); return 0; } } rv = intfstream_get_serial(fd, serial); intfstream_close(fd); free(fd); free(data); return rv; error: intfstream_close(fd); free(fd); return 0; }
static void task_database_cue_prune(database_info_handle_t *db, const char *name) { size_t i; char *path = (char *)malloc(PATH_MAX_LENGTH + 1); intfstream_t *fd = intfstream_open_file(name, RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE); if (!fd) goto end; while (cue_next_file(fd, name, path, PATH_MAX_LENGTH)) { for (i = db->list_ptr; i < db->list->size; ++i) { if (db->list->elems[i].data && !strcmp(path, db->list->elems[i].data)) { RARCH_LOG("Pruning file referenced by cue: %s\n", path); free(db->list->elems[i].data); db->list->elems[i].data = NULL; } } } end: if (fd) { intfstream_close(fd); free(fd); } free(path); }
intfstream_t *intfstream_open_chd_track(const char *path, unsigned mode, unsigned hints, int32_t track) { intfstream_info_t info; intfstream_t *fd = NULL; info.type = INTFSTREAM_CHD; info.chd.track = track; fd = (intfstream_t*)intfstream_init(&info); if (!fd) return NULL; if (!intfstream_open(fd, path, mode, hints)) goto error; return fd; error: if (fd) { intfstream_close(fd); free(fd); } return NULL; }
intfstream_t *intfstream_open_memory(void *data, unsigned mode, unsigned hints, uint64_t size) { intfstream_info_t info; intfstream_t *fd = NULL; info.type = INTFSTREAM_MEMORY; info.memory.buf.data = (uint8_t*)data; info.memory.buf.size = size; info.memory.writable = false; fd = (intfstream_t*)intfstream_init(&info); if (!fd) return NULL; if (!intfstream_open(fd, NULL, mode, hints)) goto error; return fd; error: if (fd) { intfstream_close(fd); free(fd); } return NULL; }
intfstream_t* intfstream_open_file(const char *path, unsigned mode, unsigned hints) { intfstream_info_t info; intfstream_t *fd = NULL; info.type = INTFSTREAM_FILE; fd = (intfstream_t*)intfstream_init(&info); if (!fd) return NULL; if (!intfstream_open(fd, path, mode, hints)) goto error; return fd; error: if (fd) { intfstream_close(fd); free(fd); } return NULL; }
static int iso_get_serial(database_state_handle_t *db_state, database_info_handle_t *db, const char *name, char* serial) { intfstream_t *fd = open_file(name); int rv; if (!fd) return 0; rv = stream_get_serial(db_state, db, fd, serial); intfstream_close(fd); free(fd); return rv; }
static int task_database_chd_get_serial(const char *name, char* serial) { int result; intfstream_t *fd = intfstream_open_chd_track( name, RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE, CHDSTREAM_TRACK_FIRST_DATA); if (!fd) return 0; result = intfstream_get_serial(fd, serial); intfstream_close(fd); free(fd); return result; }
static int chd_get_serial(database_state_handle_t *db_state, database_info_handle_t *db, const char *name, char* serial) { intfstream_t *fd = NULL; int result; fd = open_chd_track(name, CHDSTREAM_TRACK_FIRST_DATA); if (!fd) { return 0; } result = stream_get_serial(db_state, db, fd, serial); intfstream_close(fd); return result; }
static intfstream_t* open_file(const char *path) { intfstream_info_t info; intfstream_t *fd = NULL; info.type = INTFSTREAM_FILE; fd = intfstream_init(&info); if (!fd) return NULL; if (!intfstream_open(fd, path, RFILE_MODE_READ, -1)) { intfstream_close(fd); return NULL; } return fd; }
static intfstream_t *open_chd_track(const char *path, int32_t track) { intfstream_info_t info; intfstream_t *fd = NULL; info.type = INTFSTREAM_CHD; info.chd.track = track; fd = intfstream_init(&info); if (!fd) return NULL; if (!intfstream_open(fd, path, RFILE_MODE_READ, -1)) { intfstream_close(fd); return NULL; } return fd; }
static bool task_database_chd_get_crc(const char *name, uint32_t *crc) { int rv; intfstream_t *fd = intfstream_open_chd_track( name, RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE, CHDSTREAM_TRACK_PRIMARY); if (!fd) return 0; rv = intfstream_get_crc(fd, crc); if (rv == 1) { RARCH_LOG("CHD '%s' crc: %x\n", name, *crc); } if (fd) { intfstream_close(fd); free(fd); } return rv; }
static bool playlist_read_file( playlist_t *playlist, const char *path) { unsigned i; char buf[PLAYLIST_ENTRIES][1024]; intfstream_t *file = intfstream_open_file( path, RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE); /* If playlist file does not exist, * create an empty playlist instead. */ if (!file) return true; for (i = 0; i < PLAYLIST_ENTRIES; i++) buf[i][0] = '\0'; for (playlist->size = 0; playlist->size < playlist->cap; ) { unsigned i; struct playlist_entry *entry = NULL; for (i = 0; i < PLAYLIST_ENTRIES; i++) { char *last = NULL; *buf[i] = '\0'; if (!intfstream_gets(file, buf[i], sizeof(buf[i]))) goto end; /* Read playlist entry and terminate string with NUL character * regardless of Windows or Unix line endings */ if((last = strrchr(buf[i], '\r'))) *last = '\0'; else if((last = strrchr(buf[i], '\n'))) *last = '\0'; } entry = &playlist->entries[playlist->size]; if (!*buf[2] || !*buf[3]) continue; if (*buf[0]) entry->path = strdup(buf[0]); if (*buf[1]) entry->label = strdup(buf[1]); entry->core_path = strdup(buf[2]); entry->core_name = strdup(buf[3]); if (*buf[4]) entry->crc32 = strdup(buf[4]); if (*buf[5]) entry->db_name = strdup(buf[5]); playlist->size++; } end: intfstream_close(file); free(file); return true; }
/** * video_shader_resolve_parameters: * @conf : Preset file to read from. * @shader : Shader passes handle. * * Resolves all shader parameters belonging to shaders. * * Returns: true (1) if successful, otherwise false (0). **/ bool video_shader_resolve_parameters(config_file_t *conf, struct video_shader *shader) { unsigned i; struct video_shader_parameter *param = &shader->parameters[0]; shader->num_parameters = 0; /* Find all parameters in our shaders. */ for (i = 0; i < shader->passes; i++) { intfstream_t *file = NULL; size_t line_size = 4096 * sizeof(char); char *line = NULL; const char *path = shader->pass[i].source.path; if (string_is_empty(path)) continue; #if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS) /* First try to use the more robust slang * implementation to support #includes. */ /* FIXME: The check for slang can be removed * if it's sufficiently tested for * GLSL/Cg as well, it should be the same implementation. */ if (string_is_equal(path_get_extension(path), "slang") && slang_preprocess_parse_parameters(path, shader)) continue; /* If that doesn't work, fallback to the old path. * Ideally, we'd get rid of this path sooner or later. */ #endif file = intfstream_open_file(path, RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE); if (!file) continue; line = (char*)malloc(4096 * sizeof(char)); line[0] = '\0'; /* even though the pass is set in the loop too, not all passes have parameters */ param->pass = i; while (shader->num_parameters < ARRAY_SIZE(shader->parameters) && intfstream_gets(file, line, line_size)) { int ret = sscanf(line, "#pragma parameter %63s \"%63[^\"]\" %f %f %f %f", param->id, param->desc, ¶m->initial, ¶m->minimum, ¶m->maximum, ¶m->step); if (ret < 5) continue; param->id[63] = '\0'; param->desc[63] = '\0'; if (ret == 5) param->step = 0.1f * (param->maximum - param->minimum); param->pass = i; RARCH_LOG("Found #pragma parameter %s (%s) %f %f %f %f in pass %d\n", param->desc, param->id, param->initial, param->minimum, param->maximum, param->step, param->pass); param->current = param->initial; shader->num_parameters++; param++; } free(line); intfstream_close(file); free(file); } if (conf && !video_shader_resolve_current_parameters(conf, shader)) return false; return true; }