static int file_archive_extract_cb(const char *name, const char *valid_exts, const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size, uint32_t checksum, void *userdata) { const char *ext = path_get_extension(name); struct zip_extract_userdata *data = (struct zip_extract_userdata*)userdata; /* Extract first content that matches our list. */ if (ext && string_list_find_elem(data->ext, ext)) { char new_path[PATH_MAX_LENGTH] = {0}; if (data->extraction_directory) fill_pathname_join(new_path, data->extraction_directory, path_basename(name), sizeof(new_path)); else fill_pathname_resolve_relative(new_path, data->zip_path, path_basename(name), sizeof(new_path)); data->first_extracted_file_path = strdup(new_path); data->found_content = file_archive_perform_mode(new_path, valid_exts, cdata, cmode, csize, size, 0, NULL); return 0; } return 1; }
void makeflow_wrapper_umbrella_set_input_files(struct makeflow_wrapper_umbrella *w, struct batch_queue *queue, struct dag_node *n) { bool remote_rename_support = false; if(!w) return; // every rule may have its own umbrella spec file. // to avoid w->wrapper->input_files accumulating umbrella spec files for different rules, first delete it and then recreate it. list_delete(w->wrapper->input_files); w->wrapper->input_files = list_create(); if(!n->umbrella_spec) return; if (batch_queue_supports_feature(queue, "remote_rename")) { remote_rename_support = true; } // add umbrella_spec (if specified) and umbrella_binary (if specified) into the input file list of w->wrapper if (!remote_rename_support) { makeflow_wrapper_add_input_file(w->wrapper, n->umbrella_spec); if(w->binary) makeflow_wrapper_add_input_file(w->wrapper, w->binary); } else { { char *s = string_format("%s=%s", n->umbrella_spec, path_basename(n->umbrella_spec)); if(!s) fatal("string_format for umbrella spec failed: %s.\n", strerror(errno)); makeflow_wrapper_add_input_file(w->wrapper, s); free(s); } if(w->binary) { char *s = string_format("%s=%s", w->binary, path_basename(w->binary)); if(!s) fatal("string_format for umbrella binary failed: %s.\n", strerror(errno)); makeflow_wrapper_add_input_file(w->wrapper, s); free(s); } } }
static void OnListModule(void* param, const char* name) { Result* result = (Result*)param; if(streq(path_basename(result->module), path_basename(name))) { result->result = 0; // find it } }
static int zip_extract_cb(const char *name, const char *valid_exts, const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size, uint32_t checksum, void *userdata) { struct zip_extract_userdata *data = (struct zip_extract_userdata*)userdata; /* Extract first content that matches our list. */ const char *ext = path_get_extension(name); if (ext && string_list_find_elem(data->ext, ext)) { char new_path[PATH_MAX_LENGTH] = {0}; if (data->extraction_directory) fill_pathname_join(new_path, data->extraction_directory, path_basename(name), sizeof(new_path)); else fill_pathname_resolve_relative(new_path, data->zip_path, path_basename(name), sizeof(new_path)); switch (cmode) { case ZLIB_MODE_UNCOMPRESSED: data->found_content = zlib_write_file(new_path, cdata, size); return false; case ZLIB_MODE_DEFLATE: { int ret = 0; zlib_file_handle_t handle = {0}; if (!zlib_inflate_data_to_file_init(&handle, cdata, csize, size)) return 0; do{ ret = zlib_inflate_data_to_file_iterate(handle.stream); }while(ret == 0); if (zlib_inflate_data_to_file(&handle, ret, new_path, valid_exts, cdata, csize, size, checksum)) { strlcpy(data->zip_path, new_path, data->zip_path_size); data->found_content = true; return 0; } return 0; } default: return 0; } } return 1; }
static void netplay_announce(void) { char buf [2048]; char url [2048] = "http://newlobby.libretro.com/add/"; char *username = NULL; char *corename = NULL; char *gamename = NULL; char *coreversion = NULL; char *frontend_ident = NULL; settings_t *settings = config_get_ptr(); rarch_system_info_t *system = runloop_get_system_info(); uint32_t content_crc = content_get_crc(); char frontend_architecture[PATH_MAX_LENGTH]; netplay_get_architecture(frontend_architecture, sizeof(frontend_architecture)); net_http_urlencode(&username, settings->paths.username); net_http_urlencode(&corename, system->info.library_name); net_http_urlencode(&gamename, !string_is_empty(path_basename(path_get(RARCH_PATH_BASENAME))) ? path_basename(path_get(RARCH_PATH_BASENAME)) : "N/A"); net_http_urlencode(&coreversion, system->info.library_version); net_http_urlencode(&frontend_ident, frontend_architecture); buf[0] = '\0'; snprintf(buf, sizeof(buf), "username=%s&core_name=%s&core_version=%s&" "game_name=%s&game_crc=%08X&port=%d&mitm_server=%s" "&has_password=%d&has_spectate_password=%d&force_mitm=%d&retroarch_version=%s&frontend=%s", username, corename, coreversion, gamename, content_crc, settings->uints.netplay_port, settings->arrays.netplay_mitm_server, *settings->paths.netplay_password ? 1 : 0, *settings->paths.netplay_spectate_password ? 1 : 0, settings->bools.netplay_use_mitm_server, PACKAGE_VERSION, frontend_architecture); #if 0 RARCH_LOG("[netplay] announcement URL: %s\n", buf); #endif task_push_http_post_transfer(url, buf, true, NULL, netplay_announce_cb, NULL); if (username) free(username); if (corename) free(corename); if (gamename) free(gamename); if (coreversion) free(coreversion); if (frontend_ident) free(frontend_ident); }
static INT64_T chirp_fs_confuga_open (const char *path, INT64_T flags, INT64_T mode) { int rc; char *data = NULL; int fd = getfd(); strncpy(open_files[fd].path, path, sizeof(open_files[fd].path)-1); switch (flags & O_ACCMODE) { case O_RDONLY: if (strncmp(path_basename(path), ".__", 3) == 0) { size_t len; buffer_init(&open_files[fd].f.metadata); CATCH(confuga_metadata_lookup(C, path, &data, &len)); CATCHUNIX(buffer_putlstring(&open_files[fd].f.metadata, data, len)); open_files[fd].type = CHIRP_FS_CONFUGA_META_READ; } else { confuga_fid_t fid; CATCH_CONFUGA(confuga_lookup(C, path, &fid, NULL)); CATCH_CONFUGA(confuga_replica_open(C, fid, &open_files[fd].f.replica, STOPTIME)); open_files[fd].type = CHIRP_FS_CONFUGA_REPL_READ; } break; case O_WRONLY: if (strncmp(path_basename(path), ".__", 3) == 0) { buffer_init(&open_files[fd].f.metadata); open_files[fd].type = CHIRP_FS_CONFUGA_META_WRITE; } else { CATCH_CONFUGA(confuga_file_create(C, &open_files[fd].f.file.file, STOPTIME)); open_files[fd].f.file.size = 0; open_files[fd].f.file.flags = 0; if (flags & O_EXCL) open_files[fd].f.file.flags |= CONFUGA_O_EXCL; open_files[fd].type = CHIRP_FS_CONFUGA_FILE_WRITE; } break; case O_RDWR: CATCH(EINVAL); default: assert(0); } rc = 0; goto out; out: free(data); if (rc) return (errno = rc, -1); else return fd; /* N.B. return fd on success */ }
static int OnListProcess(void* param, const char* name, process_t pid) { Result* result = (Result*)param; if(streq(path_basename(name), path_basename(result->name))) { process_getmodules(pid, OnListModule, param); if(0 == result->result) { *result->pid = pid; return 1; } } return 0; }
static int file_archive_extract_cb(const char *name, const char *valid_exts, const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size, uint32_t checksum, struct archive_extract_userdata *userdata) { const char *ext = path_get_extension(name); /* Extract first file that matches our list. */ if (ext && string_list_find_elem(userdata->ext, ext)) { char new_path[PATH_MAX_LENGTH]; char wanted_file[PATH_MAX_LENGTH]; const char *delim = NULL; new_path[0] = wanted_file[0] = '\0'; if (userdata->extraction_directory) fill_pathname_join(new_path, userdata->extraction_directory, path_basename(name), sizeof(new_path)); else fill_pathname_resolve_relative(new_path, userdata->archive_path, path_basename(name), sizeof(new_path)); userdata->first_extracted_file_path = strdup(new_path); delim = path_get_archive_delim(userdata->archive_path); if (delim) { strlcpy(wanted_file, delim + 1, sizeof(wanted_file)); if (!string_is_equal_noncase(userdata->extracted_file_path, wanted_file)) return 1; /* keep searching for the right file */ } else strlcpy(wanted_file, userdata->archive_path, sizeof(wanted_file)); if (file_archive_perform_mode(new_path, valid_exts, cdata, cmode, csize, size, 0, userdata)) userdata->found_file = true; return 0; } return 1; }
static INT64_T do_put(int argc, char **argv) { char target_full_path[CHIRP_PATH_MAX]; char source_full_path[CHIRP_PATH_MAX]; timestamp_t start, stop; double elapsed; INT64_T result; if(!argv[2]) argv[2] = (char *) path_basename(argv[1]); complete_local_path(argv[1], source_full_path); complete_remote_path(argv[2], target_full_path); start = timestamp_get(); result = chirp_recursive_put(current_host, source_full_path, target_full_path, stoptime); stop = timestamp_get(); elapsed = (stop - start) / 1000000.0; if(result > 0) { printf("%sB written in %.2fs ", string_metric(result, -1, 0), elapsed); printf("(%sB/s)\n", string_metric(result / elapsed, -1, 0)); } return result; }
/* Returns the filename extension. * * To extract multiple extensions (e.g. .tar.gz) call path_extension multiple * times and concatenate the results. */ const char *path_extension (const char *path) { const char *base = path_basename(path); const char *dot = strrchr(base, '.'); if(!dot || dot == base) return NULL; return dot + 1; }
/* Creates and adds an example file. */ static char *add_example(struct manifest *m, struct ccan_file *source, struct doc_section *example) { char *name, *linemarker; unsigned int i; int fd; struct ccan_file *f; name = tal_fmt(m, "example-%s-%s", source->name, example->function); /* example->function == 'struct foo' */ while (strchr(name, ' ')) *strchr(name, ' ') = '_'; name = temp_file(m, ".c", take(name)); f = new_ccan_file(m, take(path_dirname(m, name)), take(path_basename(m, name))); tal_steal(f, name); list_add_tail(&m->examples, &f->list); fd = open(f->fullname, O_WRONLY | O_CREAT | O_EXCL, 0600); if (fd < 0) return tal_fmt(m, "Creating temporary file %s: %s", f->fullname, strerror(errno)); /* Add #line to demark where we are from, so errors are correct! */ linemarker = tal_fmt(f, "#line %i \"%s\"\n", example->srcline+2, source->fullname); if (write(fd, linemarker, strlen(linemarker)) != (int)strlen(linemarker)) { close(fd); return cast_const(char *, "Failure writing to temporary file"); }
bool core_info_database_supports_content_path(const char *database_path, const char *path) { size_t i; char *database = NULL; if (!core_info_curr_list) return false; database = strdup(path_basename(database_path)); path_remove_extension(database); for (i = 0; i < core_info_curr_list->count; i++) { const core_info_t *info = &core_info_curr_list->list[i]; if (string_list_find_elem(info->supported_extensions_list, path_get_extension(path))) if (string_list_find_elem(info->databases_list, database)) { free(database); return true; } } free(database); return false; }
/** * fill_short_pathname_representation: * @out_rep : output representation * @in_path : input path * @size : size of output representation * * Generates a short representation of path. It should only * be used for displaying the result; the output representation is not * binding in any meaningful way (for a normal path, this is the same as basename) * In case of more complex URLs, this should cut everything except for * the main image file. * * E.g.: "/path/to/game.img" -> game.img * "/path/to/myarchive.7z#folder/to/game.img" -> game.img */ void fill_short_pathname_representation(char* out_rep, const char *in_path, size_t size) { char path_short[PATH_MAX_LENGTH]; #ifdef HAVE_COMPRESSION char *last_slash = NULL; #endif path_short[0] = '\0'; fill_pathname(path_short, path_basename(in_path), "", sizeof(path_short)); #ifdef HAVE_COMPRESSION last_slash = find_last_slash(path_short); if (last_slash != NULL) { /* We handle paths like: * /path/to/file.7z#mygame.img * short_name: mygame.img: * * We check whether something is actually * after the hash to avoid going over the buffer. */ retro_assert(strlen(last_slash) > 1); strlcpy(out_rep, last_slash + 1, size); } else #endif strlcpy(out_rep, path_short, size); }
char *path_remove_extension(char *path) { char *last = (char*)strrchr(path_basename(path), '.'); if (*last) *last = '\0'; return last; }
static int action_ok_remap_file_save_game(const char *path, const char *label, unsigned type, size_t idx) { global_t *global = global_get_ptr(); settings_t *settings = config_get_ptr(); const char *core_name; core_name = global->system.info.library_name; const char *game_name; game_name = path_basename(global->basename); char directory[PATH_MAX_LENGTH]; char file[PATH_MAX_LENGTH]; fill_pathname_join(directory,settings->input_remapping_directory,core_name,PATH_MAX_LENGTH); fill_pathname_join(file,core_name,game_name,PATH_MAX_LENGTH); if(!path_file_exists(directory)) path_mkdir(directory); if(input_remapping_save_file(file)) rarch_main_msg_queue_push("Remap file saved successfully", 1, 100, true); else rarch_main_msg_queue_push("Error saving remap file", 1, 100, true); return 0; }
/** * Reads symbolic link destination from sysfs, and copies it to * auto-allocated string `aas`. * * @param aas auto-allocated string * @param basename if this flag is set, take basename of link destination \ * before copying * * @return HI_LINUX_SYSFS_OK if everything went fine or HI_LINUX_SYSFS_ERROR if \ * `path_join_aas()` or `readlink()` were failed */ int hi_linux_sysfs_readlink_aas(const char* root, const char* name, const char* object, char** aas, boolean_t basename) { AUTOSTRING char* path; char link[PATHMAXLEN]; ssize_t link_sz; if(path_join_aas(&path, root, name, object, NULL) == NULL) { hi_sysfs_dprintf("hi_linux_sysfs_readlink_aas: failed to do path_join\n"); return HI_LINUX_SYSFS_ERROR; } link_sz = readlink(path, link, PATHMAXLEN); if(link_sz == -1) { hi_sysfs_dprintf("hi_linux_sysfs_readlink_aas: failed to readlink(): errno = %d\n", errno); return HI_LINUX_SYSFS_ERROR; } link[link_sz] = '\0'; hi_sysfs_dprintf("hi_linux_sysfs_readlink_aas: %s/%s/%s => %s\n", root, name, object, link); if(basename) { path_split_iter_t iter; aas_copy(aas, path_basename(&iter, link)); } else { aas_copy(aas, link); } return HI_LINUX_SYSFS_OK; }
const char *path_get_extension(const char *path) { const char *ext = strrchr(path_basename(path), '.'); if (ext) return ext + 1; return ""; }
/** * fill_short_pathname_representation: * @out_rep : output representation * @in_path : input path * @size : size of output representation * * Generates a short representation of path. It should only * be used for displaying the result; the output representation is not * binding in any meaningful way (for a normal path, this is the same as basename) * In case of more complex URLs, this should cut everything except for * the main image file. * * E.g.: "/path/to/game.img" -> game.img * "/path/to/myarchive.7z#folder/to/game.img" -> game.img */ void fill_short_pathname_representation(char* out_rep, const char *in_path, size_t size) { char path_short[PATH_MAX_LENGTH] = {0}; char *last_hash = NULL; fill_pathname(path_short, path_basename(in_path), "", sizeof(path_short)); last_hash = (char*)strchr(path_short,'#'); /* We handle paths like: * /path/to/file.7z#mygame.img * short_name: mygame.img: */ if(last_hash != NULL) { /* We check whether something is actually * after the hash to avoid going over the buffer. */ rarch_assert(strlen(last_hash) > 1); strlcpy(out_rep,last_hash + 1, size); } else strlcpy(out_rep,path_short, size); }
static void lakka_init_items(lakka_handle_t *lakka, int i, menu_category_t *category, core_info_t *info, const char* path) { int num_items, j; struct string_list *list = NULL; if (category == NULL || info == NULL) return; list = (struct string_list*)dir_list_new(path, info->supported_extensions, true); dir_list_sort(list, true); num_items = list ? list->size : 0; for (j = 0; j < num_items; j++) { if (list->elems[j].attr.i == RARCH_DIRECTORY) // is a directory lakka_init_items(lakka, i, category, info, list->elems[j].data); else { lakka_init_item(lakka, i, j, category, info, list, path_basename(list->elems[j].data)); } } string_list_free(list); }
/** * fill_short_pathname_representation: * @out_rep : output representation * @in_path : input path * @size : size of output representation * * Generates a short representation of path. It should only * be used for displaying the result; the output representation is not * binding in any meaningful way (for a normal path, this is the same as basename) * In case of more complex URLs, this should cut everything except for * the main image file. * * E.g.: "/path/to/game.img" -> game.img * "/path/to/myarchive.7z#folder/to/game.img" -> game.img */ void fill_short_pathname_representation_wrapper(char* out_rep, const char *in_path, size_t size) { #ifdef HAVE_COMPRESSION char *path_short = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char *last_slash = NULL; path_short[0] = '\0'; fill_pathname(path_short, path_basename(in_path), "", PATH_MAX_LENGTH * sizeof(char) ); last_slash = find_last_slash(path_short); if (last_slash != NULL) { /* We handle paths like: * /path/to/file.7z#mygame.img * short_name: mygame.img: * * We check whether something is actually * after the hash to avoid going over the buffer. */ retro_assert(strlen(last_slash) > 1); strlcpy(out_rep, last_slash + 1, size); free(path_short); return; } free(path_short); #endif fill_short_pathname_representation(out_rep, in_path, size); }
static void menu_action_setting_disp_set_label_core_option_create( file_list_t* list, unsigned *w, unsigned type, unsigned i, const char *label, char *s, size_t len, const char *entry_label, const char *path, char *s2, size_t len2) { rarch_system_info_t *system = NULL; global_t *global = global_get_ptr(); runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); if (!system) return; *s = '\0'; *w = 19; strlcpy(s, "", len); if (!string_is_empty(global->name.base)) strlcpy(s, path_basename(global->name.base), len); strlcpy(s2, path, len2); }
static int action_start_playlist_association(unsigned type, const char *label) { int found; char new_playlist_cores[PATH_MAX_LENGTH] = {0}; struct string_list *stnames = NULL; struct string_list *stcores = NULL; core_info_list_t *list = NULL; settings_t *settings = config_get_ptr(); const char *path = path_basename(label); core_info_ctl(CORE_INFO_CTL_LIST_GET, &list); if (!list) return -1; stnames = string_split(settings->playlist_names, ";"); stcores = string_split(settings->playlist_cores, ";"); found = string_list_find_elem(stnames, path); if (found) string_list_set(stcores, found-1, "DETECT"); string_list_join_concat(new_playlist_cores, sizeof(new_playlist_cores), stcores, ";"); strlcpy(settings->playlist_cores, new_playlist_cores, sizeof(settings->playlist_cores)); return 0; }
/* * Place the directory entry tree @branch at the path @target_tstr in the WIM * image. * * @target_tstr cannot contain trailing slashes, and all path separators must be * WIM_PATH_SEPARATOR. * * On success, @branch is committed to the journal @j. * Otherwise @branch is freed. * * The relevant @add_flags are WIMLIB_ADD_FLAG_NO_REPLACE and * WIMLIB_ADD_FLAG_VERBOSE. */ static int attach_branch(struct wim_dentry *branch, const tchar *target_tstr, struct update_command_journal *j, int add_flags, wimlib_progress_func_t progfunc, void *progctx) { int ret; const utf16lechar *target; ret = 0; if (unlikely(!branch)) goto out; ret = tstr_get_utf16le(target_tstr, &target); if (ret) goto out_free_branch; BUILD_BUG_ON(WIM_PATH_SEPARATOR != OS_PREFERRED_PATH_SEPARATOR); ret = dentry_set_name(branch, path_basename(target_tstr)); if (ret) goto out_free_target; ret = do_attach_branch(branch, target, j, add_flags, progfunc, progctx); if (ret) goto out_free_target; /* branch was successfully committed to the journal */ branch = NULL; out_free_target: tstr_put_utf16le(target); out_free_branch: free_dentry_tree(branch, j->lookup_table); out: return ret; }
static int action_start_playlist_association(unsigned type, const char *label) { int found; char new_playlist_cores[PATH_MAX_LENGTH]; struct string_list *stnames = NULL; struct string_list *stcores = NULL; core_info_list_t *list = NULL; settings_t *settings = config_get_ptr(); const char *path = path_basename(label); core_info_get_list(&list); if (!list) return -1; new_playlist_cores[0] = '\0'; stnames = string_split(settings->arrays.playlist_names, ";"); stcores = string_split(settings->arrays.playlist_cores, ";"); found = string_list_find_elem(stnames, path); if (found) string_list_set(stcores, found-1, file_path_str(FILE_PATH_DETECT)); string_list_join_concat(new_playlist_cores, sizeof(new_playlist_cores), stcores, ";"); strlcpy(settings->arrays.playlist_cores, new_playlist_cores, sizeof(settings->arrays.playlist_cores)); string_list_free(stcores); string_list_free(stnames); return 0; }
char *get_rule_number(char *filename) { char name[MAX_LINE]; const char *base = path_basename(filename); sscanf(base, RULE_PREFIX "%6c" RULE_SUFFIX, name); return xxstrdup(name); }
static void path_basename_sans_extname (char *path) { if (NULL == (path = SLpath_pathname_sans_extname (path))) return; path_basename (path); SLfree (path); }
/** * Returns the length of the directory part of the filename. */ int path_dirname_len(const char *filename) { if (filename == NULL) { return(0); } return((int)(path_basename(filename) - filename)); }
/** * path_get_extension: * @path : path * * Gets extension of file. Only '.'s * after the last slash are considered. * * Returns: extension part from the path. */ const char *path_get_extension(const char *path) { const char *ext = !string_is_empty(path) ? strrchr(path_basename(path), '.') : NULL; if (!ext) return ""; return ext + 1; }
static int playlist_association_right(unsigned type, const char *label, bool wraparound) { char core_path[PATH_MAX_LENGTH]; char new_playlist_cores[PATH_MAX_LENGTH]; size_t i, next, found, current = 0; core_info_t *info = NULL; struct string_list *stnames = NULL; struct string_list *stcores = NULL; core_info_list_t *list = NULL; settings_t *settings = config_get_ptr(); const char *path = path_basename(label); core_info_get_list(&list); if (!list) return menu_cbs_exit(); core_path[0] = new_playlist_cores[0] = '\0'; stnames = string_split(settings->arrays.playlist_names, ";"); stcores = string_split(settings->arrays.playlist_cores, ";"); if (!menu_content_playlist_find_associated_core(path, core_path, sizeof(core_path))) strlcpy(core_path, file_path_str(FILE_PATH_DETECT), sizeof(core_path)); for (i = 0; i < list->count; i++) { core_info_t *info = core_info_get(list, i); if (string_is_equal(info->path, core_path)) current = i; } next = current + 1; if (next >= list->count) { if (wraparound) next = 0; else next = list->count-1; } info = core_info_get(list, next); found = string_list_find_elem(stnames, path); if (found && info) string_list_set(stcores, (unsigned)(found-1), info->path); string_list_join_concat(new_playlist_cores, sizeof(new_playlist_cores), stcores, ";"); strlcpy(settings->arrays.playlist_cores, new_playlist_cores, sizeof(settings->arrays.playlist_cores)); string_list_free(stnames); string_list_free(stcores); return 0; }
void fill_pathname_dir(char *in_dir, const char *in_basename, const char *replace, size_t size) { const char *base = NULL; fill_pathname_slash(in_dir, size); base = path_basename(in_basename); rarch_assert(strlcat(in_dir, base, size) < size); rarch_assert(strlcat(in_dir, replace, size) < size); }