int bi_cd(char **arg, t_duo **env) { char *tmp; char *path; int i; int ret; (void)env; i = 1; ret = 0; tmp = NULL; path = NULL; if (handle_cd_arg(&i, &ret, arg) == FALSE) return (FALSE); if (ret == TRUE) { tmp = get_env("PWD"); change_env("OLDPWD", tmp); path = getcwd(path, MAX_PATH); change_env("PWD", path); } ft_strdel(&tmp); ft_strdel(&path); return (FALSE); }
void setvareq(char *s, int flags) { struct var *vp, **vpp; int len; if (aflag) flags |= VEXPORT; vpp = hashvar(s); for (vp = *vpp ; vp ; vp = vp->next) { if (varequal(s, vp->text)) { if (vp->flags & VREADONLY) { len = strchr(s, '=') - s; error("%.*s: is read only", len, s); } INTOFF; if (vp->func && (flags & VNOFUNC) == 0) (*vp->func)(strchr(s, '=') + 1); if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0) ckfree(vp->text); vp->flags &= ~(VTEXTFIXED|VSTACK|VUNSET); vp->flags |= flags; vp->text = s; /* * We could roll this to a function, to handle it as * a regular variable function callback, but why bother? */ if (vp == &vmpath || (vp == &vmail && ! mpathset())) chkmail(1); if ((vp->flags & VEXPORT) && localevar(s)) { change_env(s, 1); (void) setlocale(LC_ALL, ""); } INTON; return; } } /* not found */ vp = ckmalloc(sizeof (*vp)); vp->flags = flags; vp->text = s; vp->next = *vpp; vp->func = NULL; INTOFF; *vpp = vp; if ((vp->flags & VEXPORT) && localevar(s)) { change_env(s, 1); (void) setlocale(LC_ALL, ""); } INTON; }
int ms_builtins_search_exec2(t_context *context, t_command *cmd, int outfd) { int shift; if (ft_strcmp("env", cmd->argv[0]) == 0) { if (!(shift = ms_builtin_env(context, cmd->argv, outfd))) return (0); else { cmd->null_env = change_env(cmd); cool_free(cmd->argv[0]); cool_free(cmd->argv[1]); cmd->argv = cmd->argv + shift; return (-1); } } if (ft_strcmp("exit", cmd->argv[0]) == 0) ms_builtin_exit(context, cmd->argv, outfd); if (is_a_var_set(cmd->argv[0])) return (ms_builtin_setvar(context, cmd->argv, outfd)); if (ft_strcmp("export", cmd->argv[0]) == 0) return (ms_builtin_export(context, cmd->argv, outfd)); if (ft_strcmp("unset", cmd->argv[0]) == 0) return (ms_builtin_unset(context, cmd->argv, outfd)); return (-1); }
/* Restore an old setting returned by set_tz. It must not be null. Return true (preserving errno) if successful, false (setting errno) otherwise. */ static bool revert_tz (timezone_t tz) { if (tz == local_tz) return true; else { int saved_errno = errno; bool ok = change_env (tz); if (!ok) saved_errno = errno; tzfree (tz); errno = saved_errno; return ok; } }
void set_setenv(char **av, char ***env) { char *str; if (ft_tablen(av) == 3) { if (ft_getenv(*env, av[1]) == NULL) { str = ft_strjoin(av[1], "="); str = ft_strjoin(str, av[2]); *env = ft_tabjoin(*env, str); } else change_env(*env, av[1], av[2]); } else if (ft_tablen(av) > 3) error(TOOMUCHARG, NULL); else error(TOOFEWARG, NULL); }
void setenv_shell2(char **environ, char *str, t_sh *sh) { int ref_env; int i; i = 0; sh->temp2 = xmalloc(sizeof(char *) * 3); while (i < 3) sh->temp2[i++] = xmalloc(sizeof(char) * 100); sh->temp2 = set_temp2(sh->temp2, str); if (verif_ref(sh->temp2) == 3) { if ((ref_env = check_var_to_env(sh->temp2[1], environ)) != -1) change_env(sh->temp2, environ, ref_env); else add_to_env(sh->temp2, environ); } else my_putstr("Syntaxe error\n\n"); }
/* Temporarily set the time zone to TZ, which must not be null. Return LOCAL_TZ if the time zone setting is already correct. Otherwise return a newly allocated time zone representing the old setting, or NULL (setting errno) on failure. */ static timezone_t set_tz (timezone_t tz) { char *env_tz = getenv_TZ (); if (env_tz ? tz->tz_is_set && strcmp (tz->abbrs, env_tz) == 0 : !tz->tz_is_set) return local_tz; else { timezone_t old_tz = tzalloc (env_tz); if (!old_tz) return old_tz; if (! change_env (tz)) { int saved_errno = errno; tzfree (old_tz); errno = saved_errno; return NULL; } return old_tz; } }
static int sh_lvl(void) { char *lvl; char *new_lvl; lvl = NULL; if ((lvl = get_env("SHLVL")) == NULL || ft_strcmp(lvl, "-") == 0 || ft_isstrnum(lvl) == 0 || ft_strlen(lvl) > 10) { if ((lvl = ft_strdup("0")) == NULL) return (error_clear_str(FALSE, 6, NULL, &lvl)); } new_lvl = ft_itoa(ft_atoi(lvl) + 1); if (new_lvl[0] == '-') { if ((new_lvl = ft_strdup("-")) == NULL) return (error_clear_str(FALSE, 6, NULL, &lvl)); } change_env("SHLVL", new_lvl); ft_strdel(&lvl); ft_strdel(&new_lvl); return (TRUE); }