void ft_env_u(t_all *all) { char **env_dup; char **env_bak; char **arg_dup; env_bak = NULL; if (!ft_strcmp(all->ch_arg[1], "-u")) { if (!all->ch_arg[2]) disp_missing_arg(); else { arg_dup = str_array_dup(all->ch_arg, 3); env_dup = str_array_dup(all->envp, 0); cut_env(all, &env_dup); if (!all->ch_arg[3]) disp_env(env_dup); else manage_u(all, &env_bak, &env_dup, &arg_dup); (env_dup) ? free_string_array(&env_dup) : 0; (arg_dup) ? free_string_array(&arg_dup) : 0; (env_bak) ? free_string_array(&env_bak) : 0; } } }
int gen_twrp_md5sum(const char* backup_path) { char md5file[PATH_MAX]; int numFiles = 0; ui_print("\n>> Generating md5 sum...\n"); ensure_path_mounted(backup_path); // this will exclude subfolders! char** files = gather_files(backup_path, "", &numFiles); if (numFiles == 0) { LOGE("No files found in backup path %s\n", backup_path); free_string_array(files); return -1; } int i = 0; for(i = 0; i < numFiles; i++) { ui_quick_reset_and_show_progress(1, 0); ui_print(" - %s\n", BaseName(files[i])); sprintf(md5file, "%s.md5", files[i]); if (write_md5digest(files[i], md5file, 0) < 0) { LOGE("Error while generating md5sum!\n"); ui_reset_progress(); free_string_array(files); return -1; } } ui_print("MD5 sum created.\n"); ui_reset_progress(); free_string_array(files); return 0; }
/* * GPHD_HA_release_nodes * * Free the memory allocated for the data structure holding the HA configuration */ void GPHD_HA_release_nodes(NNHAConf *conf) { if (!conf) return; pfree(conf->nameservice); free_string_array(conf->nodes, conf->numn); free_string_array(conf->rpcports, conf->numn); free_string_array(conf->restports, conf->numn); pfree(conf); }
int set_trash_dir(const char new_specs[]) { char **dirs = NULL; int ndirs = 0; int error; char *free_this; char *spec; error = 0; free_this = strdup(new_specs); spec = free_this; for(;;) { char *const p = until_first(spec, ','); const int last_element = *p == '\0'; *p = '\0'; if(!validate_spec(spec)) { error = 1; break; } ndirs = add_to_string_array(&dirs, ndirs, 1, spec); if(last_element) { break; } spec = p + 1; } free(free_this); if(!error) { free_string_array(specs, nspecs); specs = dirs; nspecs = ndirs; copy_str(cfg.trash_dir, sizeof(cfg.trash_dir), new_specs); } else { free_string_array(dirs, ndirs); } return error; }
static void free_menu_serverlist (void) // jitodo -- eh, something should call this? { if (m_serverlist.info) free_string_array(m_serverlist.info, m_serverlist.nummapped); if (m_serverlist.ips) free_string_array(m_serverlist.ips, m_serverlist.nummapped); if (m_serverlist.server) Z_Free(m_serverlist.server); memset(&m_serverlist, 0, sizeof(m_serverlist_t)); }
/* Arguements: -(char **): Array of elements Returns (void) */ static void redirect_append(char **array) { if ( (! array) || (! array[0]) || (! array[1])) return; char **arguements = arguementify( array[0] ); int fd = open( array[1], O_WRONLY | O_CREAT | O_EXCL, 0644); if (fd == -1) fd = open( array[1], O_WRONLY | O_APPEND ); // If I can't really open the file... if (fd == -1) { print_error("open", errno); return; } // Otherwise, keep going int new_stdout = dup(STDOUT_FILENO); dup2(fd, STDOUT_FILENO); execute_command( arguements ); // Cleanup dup2(new_stdout, STDOUT_FILENO); close(fd); close(new_stdout); free_string_array(arguements); }
int replace_fsaves(FILE *f, char *parent, fsave *list, int nfs, int *found) { // To replace nfs fsaves in the top-level container container_name, // within a file. For now, if you want to replace a list within a // non-top-level container, just position the file at the beginning // of its parent container (the file won't be rewound). // // This function only works with constant-size fsaves, so if you use this // make sure it's pre-allocated or you'll corrupt the file. int i, rv = 0; fsave fp = null_fs(); flocs inf = null_flocs(); int null_f = (found == NULL); int *locs = NULL; char **names = NULL; if(f == NULL) { rv = MCF_ERR_NOFILE; goto error; } if(list == NULL || nfs < 1) { rv = MCF_ERR_FLOC_NAME; goto error; } long pos = find_fsave_in_file(f, parent, MCF_WRAP); if(pos < 0) { rv = pos; goto error; } fseek(f, pos, SEEK_SET); if(rv = get_fs_header_from_file(f, &fp)) { goto error; } names = calloc(nfs, sizeof(char *)); for(i = 0; i < nfs; i++) { names[i] = malloc(list[i].ns); memcpy(names[i], list[i].name, list[i].ns); } inf = read_flocs_from_file(f, &rv, fp.size); locs = strings_in_array(inf.name, names, inf.num, nfs); if(null_f) { found = calloc(nfs, sizeof(int)); } else { memset(found, 0, sizeof(int)*nfs); } for(i = 0; i < nfs; i++) { if(!(found[i] = (locs[i] >= 0))) { continue; } fseek(f, inf.pos[locs[i]], SEEK_SET); fwrite(list[i].val.c, sizeof(char), list[i].size, f); } error: if(locs != NULL) { free(locs); } if(null_f && found != NULL) { free(found); } free_string_array(names, nfs); free_fsave(&fp); free_flocs(&inf); return rv; }
BOOL load_dictionary(void) { char buffer[4096] = { 0 }; FILE *fh = fopen(dictionary_file, "r"); if (!fh) return FALSE; free_string_array(&dictionary); while(!feof(fh)) { if (fgets(buffer, sizeof buffer, fh) == NULL) break; if (strlen(buffer) == 0) continue; terminate_str(buffer, '\r'); terminate_str(buffer, '\n'); add_to_string_array(&dictionary, buffer); } fclose(fh); sort_string_array(&dictionary); return TRUE; }
/* Sorts specified range of entries according to sorting groups option. */ static void sort_by_groups(dir_entry_t *entries, size_t nentries) { char **groups = NULL; int ngroups = 0; const int optimize = (view_sort_groups != view->sort_groups_g); int i; char *const copy = strdup(view_sort_groups); char *group = copy, *state = NULL; while((group = split_and_get(group, ',', &state)) != NULL) { ngroups = add_to_string_array(&groups, ngroups, 1, group); } free(copy); for(i = ngroups - (optimize ? 1 : 0); i >= 1; --i) { regex_t regex; (void)regcomp(®ex, groups[i], REG_EXTENDED | REG_ICASE); sort_by_key(entries, nentries, SK_BY_GROUPS, ®ex); regfree(®ex); } if(optimize && ngroups != 0) { sort_by_key(entries, nentries, SK_BY_GROUPS, &view->primary_group); } free_string_array(groups, ngroups); }
void ls_one(char *file, char *option) { DIR *dir; t_dirent *folder; char **tab; int folder_len; int j; j = 0; folder = NULL; if ((folder_len = count_nb_file(file)) == -1) display_eacces(file); else { (!(dir = opendir(file))) ? perror_opendir() : 0; if (!(tab = (char**)malloc(sizeof(*tab) * (folder_len + 1)))) perror_malloc(); while ((folder = readdir(dir))) tab[j++] = ft_strjoin_path(file, folder->d_name); tab[j] = NULL; (closedir(dir) == -1) ? perror_closedir() : 0; (IS_T && !(IS_F)) ? mod_time_sort(tab) : 0; (!(IS_F) && !(IS_T)) ? ascii_sort(tab) : 0; (IS_R_2 && !(IS_F)) ? rev_sort(tab) : 0; display_file(tab, option); free_string_array(&tab); } }
/** * bastile_gpg_options_find_vals * * @option: null terminated array of option names * @value: An array of pointers for return values * @err: Returns an error value when errors * * Find the value for a given options in the gpg config file. * Values without a value are returned as an empty string. * On success be sure to free all *value after you're done * with them. values should be at least as big as options * * Returns: TRUE if success, FALSE if not **/ gboolean bastile_gpg_options_find_vals (const gchar *options[], gchar *values[], GError **err) { GError *e = NULL; GArray *lines; const gchar **opt; gchar *line; gchar *t; guint i, j; g_assert (!err || !*err); if (!err) err = &e; if (!gpg_options_init (err)) return FALSE; lines = read_config_file (err); if (!lines) return FALSE; /* Clear out all values */ for (i = 0, opt = options; *opt != NULL; opt++, i++) values[i] = NULL; for (j = 0; j < lines->len; j++) { line = g_array_index (lines, gchar*, j); g_assert (line != NULL); g_strstrip (line); /* Ignore comments and blank lines */ if (line[0] != '#' && line[0] != 0) { for (i = 0, opt = options; *opt != NULL; opt++, i++) { if (g_str_has_prefix (line, *opt)) { t = line + strlen (*opt); if (t[0] == 0 || g_ascii_isspace (t[0])) { /* * We found a value. Fill it in. The caller * frees this stuff. Note that we don't short * circuit the search because for gpg options * can be specified multiple times, and the * last one wins. */ g_free (values[i]); values[i] = g_strdup (t); g_strstrip (values[i]); break; /* Done with this line */ } } } } } free_string_array (lines); return *err ? FALSE : TRUE; }
void vle_aucmd_remove(const char event[], const char patterns[]) { int i; int len; char **pats = get_patterns(patterns, &len); for(i = (int)DA_SIZE(autocmds) - 1; i >= 0; --i) { char pat[1U + strlen(autocmds[i].pattern) + 1U]; copy_str(&pat[1], sizeof(pat) - 1U, autocmds[i].pattern); pat[0] = autocmds[i].negated ? '!' : '='; if(event != NULL && strcasecmp(event, autocmds[i].event) != 0) { continue; } if(patterns != NULL && !is_in_string_array(pats, len, pat)) { continue; } free_autocmd_data(&autocmds[i]); DA_REMOVE(autocmds, &autocmds[i]); } free_string_array(pats, len); }
TEST(symlinks_are_not_resolved_in_tree_preview, IF(not_windows)) { int nlines; FILE *fp; char **lines; assert_success(os_mkdir(SANDBOX_PATH "/dir", 0777)); /* symlink() is not available on Windows, but the rest of the code is fine. */ #ifndef _WIN32 assert_success(symlink(".", SANDBOX_PATH "/dir/link")); #endif fp = qv_view_dir(SANDBOX_PATH "/dir"); lines = read_file_lines(fp, &nlines); assert_int_equal(4, nlines); assert_string_equal("dir/", lines[0]); assert_string_equal("`-- link/ -> .", lines[1]); assert_string_equal("", lines[2]); assert_string_equal("1 directory, 0 files", lines[3]); free_string_array(lines, nlines); fclose(fp); assert_success(unlink(SANDBOX_PATH "/dir/link")); assert_success(rmdir(SANDBOX_PATH "/dir")); }
void vle_aucmd_list(const char event[], const char patterns[], vle_aucmd_list_cb cb, void *arg) { size_t i; int len; char **pats = get_patterns(patterns, &len); for(i = 0U; i < DA_SIZE(autocmds); ++i) { char pat[1U + strlen(autocmds[i].pattern) + 1U]; copy_str(&pat[1], sizeof(pat) - 1U, autocmds[i].pattern); pat[0] = autocmds[i].negated ? '!' : '='; if(event != NULL && strcasecmp(event, autocmds[i].event) != 0) { continue; } if(patterns != NULL && !is_in_string_array(pats, len, pat)) { continue; } cb(autocmds[i].event, autocmds[i].pattern, autocmds[i].negated, autocmds[i].action, arg); } free_string_array(pats, len); }
void hist_reset(hist_t *hist, size_t size) { free_string_array(hist->items, size); hist->items = NULL; hist->pos = NO_POS; }
void complete_colorschemes(const char name[]) { int i; size_t len; int schemes_len; char **schemes; len = strlen(name); schemes = list_color_schemes(&schemes_len); for(i = 0; i < schemes_len; i++) { if(schemes[i][0] != '.' || name[0] == '.') { if(strnoscmp(name, schemes[i], len) == 0) { vle_compl_add_match(schemes[i]); } } } free_string_array(schemes, schemes_len); vle_compl_finish_group(); vle_compl_add_last_match(name); }
int show_trashes_menu(view_t *view, int calc_size) { char **trashes; int ntrashes; int i; static menu_data_t m; menus_init_data(&m, view, format_str("%sNon-empty trash directories", calc_size ? "[ size] " : ""), strdup("No non-empty trash directories found")); m.execute_handler = &execute_trashes_cb; m.key_handler = &trashes_khandler; m.extra_data = calc_size; trashes = list_trashes(&ntrashes); show_progress(NULL, 0); for(i = 0; i < ntrashes; i++) { char *const item = format_item(trashes[i], calc_size); m.len = put_into_string_array(&m.items, m.len, item); } free_string_array(trashes, ntrashes); return menus_enter(m.state, view); }
/** * bastile_gpg_options_change_vals * * @option: null-terminated array of option names to change * @value: The values to change respective option to * @err: Returns an error value when errors * * Changes the given option in the gpg config file. * If a value is NULL, the option will be deleted. If you want * an empty value, set value to an empty string. * * Returns: TRUE if success, FALSE if not **/ gboolean bastile_gpg_options_change_vals (const gchar *options[], gchar *values[], GError **err) { GError *e = NULL; GArray *lines; g_assert (!err || !*err); if (!err) err = &e; if (!gpg_options_init (err)) return FALSE; lines = read_config_file (err); if (!lines) return FALSE; process_conf_edits (lines, options, values); write_config_file (lines, err); free_string_array (lines); return *err ? FALSE : TRUE; }
void free_report(struct report_details *report) { int i; if(report == NULL) return; if(report->project_name != NULL) free(report->project_name); if(report->branches_list != NULL) free_string_array(report->branches_list, report->n_branches); if(report->hosts_list != NULL) free_string_array(report->hosts_list, report->n_hosts); if(report->jobs_list != NULL) free_string_array(report->jobs_list, report->n_jobs); if(report->users_list != NULL) free_string_array(report->users_list, report->n_users); if(report->parameters_list != NULL) free_string_array(report->parameters_list, report->n_parameters); if(report->builds != NULL) { for(i=0; i<report->n_builds; i++) { if(report->builds[i] != NULL) free(report->builds[i]); } free(report->builds); } if(report->parameters != NULL) { for(i=0; i<report->n_builds; i++) { if(report->parameters[i] != NULL) free(report->parameters[i]); } free(report->parameters); } free(report); }
/** * @brief * free_resource_resv - free a resource resv strcture an all of it's ptrs * * @param[in] resresv - resource_resv to free * * @return nothing * */ void free_resource_resv(resource_resv *resresv) { if (resresv == NULL) return; if (resresv->name != NULL) free(resresv->name); if (resresv->user != NULL) free(resresv->user); if (resresv->group != NULL) free(resresv->group); if (resresv->project != NULL) free(resresv->project); if (resresv->nodepart_name != NULL) free(resresv->nodepart_name); if (resresv->select != NULL) free_selspec(resresv->select); if (resresv->execselect != NULL) free_selspec(resresv->execselect); if (resresv->place_spec != NULL) free_place(resresv->place_spec); if (resresv->resreq != NULL) free_resource_req_list(resresv->resreq); if (resresv->ninfo_arr != NULL) free(resresv->ninfo_arr); if (resresv->nspec_arr != NULL) free_nspecs(resresv->nspec_arr); if (resresv->job != NULL) free_job_info(resresv->job); if (resresv->resv != NULL) free_resv_info(resresv->resv); if (resresv->aoename != NULL) free(resresv->aoename); if (resresv->eoename != NULL) free(resresv->eoename); if (resresv->node_set_str != NULL) free_string_array(resresv->node_set_str); if (resresv->node_set != NULL) free(resresv->node_set); free(resresv); }
void reset_popup_menu(menu_info *m) { free(m->args); /* Menu elements don't always have data associated with them. That's why we * need this check. */ if(m->data != NULL) { free_string_array(m->data, m->len); } free_string_array(m->items, m->len); free(m->regexp); free(m->matches); free(m->title); free(m->empty_msg); werase(menu_win); }
static void manage_u(t_all *all, char ***e_b, char ***e_d, char ***arg_d) { *e_b = str_array_dup(all->envp, 0); if (!ft_strcmp(all->ch_arg[2], "PATH")) all->path = NULL; if (all->my_envp) free_string_array(&all->envp); all->envp = str_array_dup(*e_d, 0); all->env_list = store_env(*e_d); all->cmd = ft_strdup(all->ch_arg[3]); all->ch_arg = str_array_dup(*arg_d, 0); manage_choice(all); if (all->my_envp) free_string_array(&all->envp); all->envp = str_array_dup(*e_b, 0); all->env_list = store_env(all->envp); all->path = get_path(all->env_list); }
static void prepare_exit(char ***envp, t_all **all, char **choice, int ret) { free_string_array(envp); (*all) ? (*all)->my_envp = 1 : 0; ft_strdel(choice); if (!ret) ft_putchar('\n'); (*all) ? free_all_list(all) : 0; }
void pb_FreeParameters(struct pb_Parameters *p) { char **cpp; free(p->outFile); free_string_array(p->inpFiles); free(p); }
void args_free(args_t *args) { if(args != NULL) { free_string_array(args->cmds, args->ncmds); args->cmds = NULL; args->ncmds = 0; } }
/* * * free_node_info - frees memory used by a node_info * * ninfo - the node to free * * returns nothing * */ void free_node_info(node_info *ninfo) { if (ninfo != NULL) { if (ninfo -> name != NULL) free(ninfo -> name); if (ninfo -> properties != NULL) free_string_array(ninfo -> properties); if (ninfo -> jobs != NULL) free_string_array(ninfo -> jobs); if (ninfo -> arch != NULL) free(ninfo -> arch); free(ninfo); } }
static void manage_env(t_all **all, char ***envp, int *run, long long *exit) { if (!(*run)) ++(*run); else (*envp) ? free_string_array(envp) : 0; (*envp) = str_array_dup((*all)->envp, 0); *exit = (*all) ? is_exit(*all) : 0; (*all) ? free_all_list(all) : 0; }
/* Formats contents of the job bar. Returns pointer to statically allocated * storage. */ static const char * format_job_bar(void) { enum { MAX_UTF_CHAR_LEN = 4 }; static char bar_text[512*MAX_UTF_CHAR_LEN + 1]; size_t i; size_t text_width; size_t width_used; size_t max_width; char **descrs; descrs = take_job_descr_snapshot(); bar_text[0] = '\0'; text_width = 0U; /* The check of stage is for tests. */ max_width = (curr_stats.load_stage < 2) ? 80 : getmaxx(job_bar); width_used = 0U; for(i = 0U; i < nbar_jobs; ++i) { const int progress = bar_jobs[i]->progress; const unsigned int reserved = (progress == -1) ? 0U : 5U; char item_text[max_width*MAX_UTF_CHAR_LEN + 1U]; const size_t width = (i == nbar_jobs - 1U) ? (max_width - width_used) : (max_width/nbar_jobs); char *const ellipsed = left_ellipsis(descrs[i], width - 2U - reserved, curr_stats.ellipsis); if(progress == -1) { snprintf(item_text, sizeof(item_text), "[%s]", ellipsed); } else { snprintf(item_text, sizeof(item_text), "[%s %3d%%]", ellipsed, progress); } free(ellipsed); (void)sstrappend(bar_text, &text_width, sizeof(bar_text), item_text); width_used += width; } free_string_array(descrs, nbar_jobs); return bar_text; }
/* Frees all resources allocated by view_info_t structure instance. */ static void free_view_info(view_info_t *vi) { free_string_array(vi->lines, vi->nlines); free(vi->widths); if(vi->last_search_backward != -1) { regfree(&vi->re); } free(vi->filename); }
/* Empties all trash directories (all specifications on all mount points are * expanded). */ static void empty_trash_dirs(void) { const trashes_list list = get_list_of_trashes(); int i; for(i = 0; i < list.ntrashes; i++) { empty_trash_dir(list.trashes[i]); } free_string_array(list.trashes, list.ntrashes); }