int main(int argc, char** argv) { set_env(); environ = NULL; test_env(); set_env(); environ[0] = NULL; test_env(); static char* emptyEnv[1] = {NULL}; set_env(); environ = emptyEnv; test_env(); set_env(); environ = (char**)calloc(1, sizeof(*environ)); test_env(); // clearenv() is not part of the POSIX specs #if 1 set_env(); clearenv(); test_env(); #endif return 0; }
static ret_t add_environment (cherokee_handler_cgi_t *cgi, cherokee_connection_t *conn) { ret_t ret; cherokee_handler_cgi_base_t *cgi_base = HDL_CGI_BASE(cgi); cherokee_buffer_t *tmp = THREAD_TMP_BUF2(CONN_THREAD(conn)); ret = cherokee_handler_cgi_base_build_envp (HDL_CGI_BASE(cgi), conn); if (unlikely (ret != ret_ok)) return ret; /* CONTENT_LENGTH */ if (http_method_with_input (conn->header.method)) { cherokee_buffer_clean (tmp); cherokee_buffer_add_ullong10 (tmp, conn->post.len); set_env (cgi_base, "CONTENT_LENGTH", tmp->buf, tmp->len); } /* SCRIPT_FILENAME */ if (cgi_base->executable.len <= 0) return ret_error; set_env (cgi_base, "SCRIPT_FILENAME", cgi_base->executable.buf, cgi_base->executable.len); return ret_ok; }
void handle_exit_status(char ***env, int child_status, char **cmds, int i) { char buf[25]; char *tmp; if (WIFEXITED(child_status) == 1) { set_env(env, "?", tmp = ft_itoa(WEXITSTATUS(child_status))); ft_strdel(&tmp); } else if (WIFSIGNALED(child_status) == 1) { set_env(env, "?", tmp = ft_itoa(child_status)); ft_strdel(&tmp); set_message(buf, WTERMSIG(child_status)); if (buf[0] != '\0') { ft_putstr_fd(singleton_state()->shell_name, 2); ft_putstr_fd(": ", 2); ft_putstr_fd(buf, 2); ft_putstr_fd(": ", 2); ft_putendl_fd(ft_remove_blank_begin_end(cmds[i]), 2); } } }
void setenv_from_config(void) { int i, lim = sizeof(envname) / sizeof(char *); STRBUF *sb = strbuf_open(0); for (i = 0; i < lim; i++) { if (getenv(envname[i]) == NULL) { strbuf_reset(sb); if (getconfs(envname[i], sb)) set_env(envname[i], strbuf_value(sb)); else if (getconfb(envname[i])) set_env(envname[i], ""); } } /* * For upper compatibility. * htags_options is deprecated. */ if (getenv("HTAGS_OPTIONS") == NULL) { strbuf_reset(sb); if (getconfs("htags_options", sb)) set_env("HTAGS_OPTIONS", strbuf_value(sb)); } strbuf_close(sb); }
bool stdenv(lisp_env *env) { /* Arithmetic, logical */ set_env(env, "+", (lisp_obj*) &lisp_add); set_env(env, "-", (lisp_obj*) &lisp_sub); set_env(env, "*", (lisp_obj*) &lisp_mul); set_env(env, "<", (lisp_obj*) &lisp_lt); set_env(env, "real", (lisp_obj*) &lisp_real); /* Repl, i/o */ set_env(env, "display", (lisp_obj*) &lisp_display); set_env(env, "exit", (lisp_obj*) &lisp_exit); /* Debug, internal */ set_env(env, "refcount", (lisp_obj*) &lisp_refcount); set_env(env, "dmp", (lisp_obj*) &lisp_dump_env); /* Lisp plumbery */ lisp_obj *res = NULL; for (size_t i=0; i<sizeof(lisp_stubs)/sizeof(lisp_stubs[0]); i++){ res = eval(lisp_stubs[i], env, NULL); if (res != NIL){ return false; } } return true; }
static void set_rd_prompt(char **pt, int lap) { if (lap == 0) { *pt = my_strdup(get_env("PS1")); set_env("PS1", "> "); return ; } set_env("PS1", *pt); free(*pt); }
int add_env( char * name, char * value ) { int res = 0 ; char * npst = getenv( name ), * vpst = NULL ; if( npst==NULL ) { res = set_env( name, value ) ; } else { vpst = (char*) malloc( strlen(npst)+strlen(value)+20 ) ; sprintf( vpst, "%s=%s;%s", name, npst, value ) ; res = set_env( name, vpst ) ; free( vpst ) ; } return res ; }
int start_win_emulator(char* emu, char *start_prog, char** argv, int start_detached) { int result; windowed = 1; if (start_detached) { char *buff; close(0); close(1); close(2); set_env("ERL_CONSOLE_MODE", "detached"); set_env(DLL_ENV, emu); argv[0] = start_prog; argv = fnuttify_argv(argv); result = spawnv(_P_DETACH, start_prog, argv); free_fnuttified(argv); } else { int argc = 0; #ifdef LOAD_BEAM_DYNAMICALLY HMODULE beam_module = load_win_beam_dll(emu); #endif set_env("ERL_CONSOLE_MODE", "window"); while (argv[argc] != NULL) { ++argc; } #ifdef ARGS_HARDDEBUG { char sbuf[2048] = ""; int i; for (i = 0; i < argc; ++i) { strcat(sbuf,"|"); strcat(sbuf, argv[i]); strcat(sbuf,"| "); } MessageBox(NULL, sbuf, "Werl", MB_OK|MB_ICONERROR); } #endif #ifdef LOAD_BEAM_DYNAMICALLY (*sys_primitive_init_p)(beam_module); (*erl_start_p)(argc,argv); #else erl_start(argc, argv); #endif result = 0; } if (result == -1) { error("Failed to execute %s: %s", emu, win32_errorstr(_doserrno)); } return 0; }
static int fastboot_data_part_wipe() { int ret = B_OK; int err; int index; #ifdef MTK_NEW_COMBO_EMMC_SUPPORT unsigned int part_id; #endif unsigned long long ptn; unsigned long long size; index = partition_get_index("userdata"); if (index == -1 || !is_support_erase(index)) { ret = PART_GET_INDEX_FAIL; return ret; } #ifdef MTK_NEW_COMBO_EMMC_SUPPORT part_id = partition_get_region(index); #endif ptn = partition_get_offset(index); size = partition_get_size(index); set_env("unlock_erase", "start"); #ifdef MTK_EMMC_SUPPORT #ifdef MTK_NEW_COMBO_EMMC_SUPPORT err = emmc_erase(part_id, ptn, size); #else err = emmc_erase(ptn, size); #endif #else err = nand_erase(ptn,(u64)size); #endif if (err) { ret = PART_ERASE_FAIL; set_env("unlock_erase", "fail"); } else { ret = B_OK; set_env("unlock_erase", "pass"); } return ret; }
void ft_setenv(char **env, char *name, char *value) { int i; int j; int g; char *e_title; i = 0; g = 0; while (env[i]) { j = 0; while (env[i][j] != '\0' && env[i][j] != '=') j++; if (env[i][j] != '\0') { e_title = ft_strsub(env[i], 0, j); if (ft_strcmp(e_title, name) == 0) { set_env(env, i, j, value); g++; } ft_memdel((void **)&e_title); } i++; } if (g == 0) add_env(env, i, name, value); }
void set_env_keyval(t_env **env, char *keyval) { char **split; if (!keyval) return ; split = ft_strsplit(keyval, '='); if (split[0] == NULL) { set_env(env, "", ft_strdup("")); } else set_env(env, split[0], split[1]); free(split[0]); free(split); }
inline static int w_exec_avp(struct sip_msg* msg, char* cmd, char* avpl) { environment_t *backup; int ret; str command; if(msg==0 || cmd==0) return -1; backup=0; if (setvars) { backup=set_env(msg); if (!backup) { LM_ERR("no env created\n"); return -1; } } if(fixup_get_svalue(msg, (gparam_p)cmd, &command)!=0) { LM_ERR("invalid command parameter"); return -1; } LM_DBG("executing [%s]\n", command.s); ret=exec_avp(msg, command.s, (pvname_list_p)avpl); if (setvars) { unset_env(backup); } return ret; }
void print_pipe_error_then_exit(t_state *state) { ft_putstr_fd(state->shell_name, 2); ft_putendl_fd(": pipe() error", 2); set_env(&state->env, "?", "1"); exit(1); }
void print_command_not_found(t_state *state, char *cmd, char *s) { ft_putstr_fd(cmd, 2); ft_putstr_fd(": command not found: ", 2); ft_putendl_fd(s, 2); set_env(&state->env, "?", "127"); }
int ft_isbuiltin(t_env *env, char *line) { char **line2; int i; t_main w; i = 0; line2 = ft_strsplit(line, ' '); if (ft_strcmp(line2[0], "echo") == 0 && (i = 1)) { line = ft_strfcut(line, 5); ft_echo(line); } else if (ft_strncmp(line, "cd", 2) == 0 && (i = 1)) ft_cd(line); else if (ft_strncmp(line, "unsetenv", 7) == 0 && (i = 1)) env = ft_unsetenv(env); else if (ft_strncmp(line, "env", 2) == 0 && (i = 1)) print_env(env); else if (ft_strncmp(line, "setenv", 5) == 0 && (i = 1)) { line = ft_strrw(line); line2 = ft_strsplit(line, ' '); env = set_env(line2, env); } if (i == 1) ft_doublecoms(env, &w, 0); return (1); }
static void load_default_env(void) { int i; char *tmp; int mum = 1; char load_buf[20]={0}; printk("[%s]load default env\n",MODULE_NAME); tmp = get_env(DATA_FREE_SIZE_TH_NAME); if(tmp == NULL){ printk("[%s]can not find %s,set the default value\n",MODULE_NAME,DATA_FREE_SIZE_TH_NAME); sprintf(load_buf,"%d",DATA_FREE_SIZE_TH_DEFAULT); set_env(DATA_FREE_SIZE_TH_NAME,load_buf); return; } for(i=0;i<strlen(tmp);i++){ if(tmp[i] == 'M' || tmp[i] == 'm'){ mum = 1024*1024; break; }else if(tmp[i] == 'K' || tmp[i] == 'k'){ mum = 1024; break; }else{ load_buf[i] = tmp[i]; } } data_free_size_th =(long long)simple_strtol(load_buf,NULL,10)*mum; printk("[%s]find %s = %llx\n",MODULE_NAME,DATA_FREE_SIZE_TH_NAME,data_free_size_th); }
inline static int w_exec_msg(struct sip_msg* msg, char* p1, char* foo) { str cmd; environment_t *backup; int ret; if (get_str_fparam(&cmd, msg, (fparam_t*)p1) < 0) { ERR("Error while obtaining command name\n"); return -1; } backup=0; if (setvars) { backup=set_env(msg); if (!backup) { LOG(L_ERR, "ERROR: w_exec_msg: no env created\n"); return -1; } } ret=exec_msg(msg, &cmd); if (setvars) { unset_env(backup); } return ret; }
int main(void) { int x; int y; int nb_it; double x_f; double y_f; double stepx; double stepy; t_env e; set_env(&e, "titre", WX, WY); x = 0; x_f = e.xmin; while (x <= WX) { y = 0; y_f = e.ymin; while (y <= WY) { nb_it = is_converg((mandelbrot), x_f, y_f); // printf("val x_f = %lf, val de y_f = %lf, val de nb_it = %d\n", x_f, y_f, nb_it); if (nb_it < 1000) mlx_pixel_put_img(e.img, x, y, rainbow_gen(nb_it * 40)); y++; y_f += e.stepy; } x_f += e.stepx; x++; } mlx_put_image_to_window(e.mlx, e.win, e.img, 0,0); mlx_mouse_hook(e.win, mouse_hook, &e); mlx_loop(e.mlx); return (0); }
void print_permission_denied(t_state *state, char *cmd, char *s) { ft_putstr_fd(cmd, 2); ft_putstr_fd(": permission denied: ", 2); ft_putendl_fd(s, 2); set_env(&state->env, "?", "126"); }
inline static int w_exec_dset(struct sip_msg* msg, char* p1, char* foo) { str cmd; str *uri; environment_t *backup; int ret; if (get_str_fparam(&cmd, msg, (fparam_t*)p1) < 0) { ERR("Error while obtaining command name\n"); return -1; } backup=0; if (setvars) { backup=set_env(msg); if (!backup) { LOG(L_ERR, "ERROR: w_exec_msg: no env created\n"); return -1; } } if (msg->new_uri.s && msg->new_uri.len) uri=&msg->new_uri; else uri=&msg->first_line.u.request.uri; ret=exec_str(msg, &cmd, uri->s, uri->len); if (setvars) { unset_env(backup); } return ret; }
void print_bad_assignment(t_state *state, char *s) { ft_putstr_fd("setenv: bad assignment: ", 2); ft_putchar_fd('`', 2); ft_putstr_fd(s, 2); ft_putendl_fd("`", 2); set_env(&state->env, "?", "0"); }
void bc_setenv(t_cfg *cfg, char **path) { if (path[1] == NULL || path[2] == NULL) return (bc_error("setenv: Missing arg. usage: setenv var value")); else if (path[3]) return (bc_error("unsetenv: Too much args. usage: setenv var value")); set_env(&(cfg->env), path[1], path[2]); }
int main(int argc, char **argv) { char *p; char *abspath; char *bindir; /* Location of executables. */ char rootdir[PATH_MAX]; /* Root location of Erlang installation. */ char progname[PATH_MAX]; /* Name of this program. */ char erlexec[PATH_MAX]; /* Path to erlexec */ /* Determine progname */ abspath = find_prog(argv[0]); strcpy(progname, abspath); for (p = progname+strlen(progname)-1;p >= progname && *p != '/'; --p) ; /* Determine bindir */ bindir = find_bindir(abspath); /* Determine rootdir */ strcpy(rootdir, bindir); for (p = rootdir+strlen(rootdir)-1;p >= rootdir && *p != '/'; --p) ; p--; for (;p >= rootdir && *p != '/'; --p) ; *p ='\0'; /* Update environment */ set_env("EMU", "beam"); set_env("PROGNAME", progname); set_env("BINDIR", bindir); set_env("ROOTDIR", rootdir); /* Invoke erlexec */ strcpy(erlexec, bindir); strcat(erlexec, DIRSEP); strcat(erlexec, "erlexec"); efree(abspath); efree(bindir); execvp(erlexec, argv); error("Error %d executing \'%s\'.", errno, erlexec); return 2; }
/** * preparse_options * * @param[in] argc * @param[in] argv * * Setup the GTAGSCONF and the GTAGSLABEL environment variable * according to the --gtagsconf and --gtagslabel option. */ void preparse_options(int argc, char *const *argv) { int i; char *p; char *confpath = NULL; char *label = NULL; char *opt_gtagsconf = "--gtagsconf"; char *opt_gtagslabel = "--gtagslabel"; for (i = 1; i < argc; i++) { p = argv[i]; if ((p = locatestring(argv[i], opt_gtagsconf, MATCH_AT_FIRST))) { if (*p == '\0') { if (++i >= argc) die("%s needs an argument.", opt_gtagsconf); confpath = argv[i]; } else { if (*p++ == '=' && *p) confpath = p; } } else if ((p = locatestring(argv[i], opt_gtagslabel, MATCH_AT_FIRST))) { if (*p == '\0') { if (++i >= argc) die("%s needs an argument.", opt_gtagslabel); label = argv[i]; } else { if (*p++ == '=' && *p) label = p; } } } if (confpath) { char real[MAXPATHLEN]; if (!test("f", confpath)) die("%s file not found.", opt_gtagsconf); if (!realpath(confpath, real)) die("cannot get absolute path of %s file.", opt_gtagsconf); set_env("GTAGSCONF", real); } if (label) set_env("GTAGSLABEL", label); }
void print_env_illegal_option(t_state *state, char c) { ft_putstr_fd("env: illegal option -- '", 2); ft_putchar_fd(c, 2); ft_putendl_fd("'", 2); ft_putstr_fd("usage: env [-i] [name=value ...]", 2); ft_putendl_fd(" [utility [argument ...]]", 2); set_env(&state->env, "?", "125"); }
void print_error_then_exit(t_state *state, char *s, char *n) { ft_putstr_fd(state->shell_name, 2); ft_putstr_fd(": ", 2); ft_putstr_fd(s, 2); ft_putendl_fd(" error", 2); set_env(&state->env, "?", n); exit(ft_atoi(n)); }
vm_obj attribute_register(vm_obj const & vm_n, vm_obj const & vm_s) { auto const & s = to_tactic_state(vm_s); auto const & n = to_name(vm_n); LEAN_TACTIC_TRY; auto env = add_user_attr(s.env(), n); env = module::add(env, *g_key, [=](environment const &, serializer & s) { s << n; }); return mk_tactic_success(set_env(s, env)); LEAN_TACTIC_CATCH(s); }
static int build_cd_tris(char **s, char ***env) { char *buf; buf = NULL; if (ft_tablen(s) == 2 && access(s[1], F_OK) == -1) return (ft_putstr_fd("Path doesn't exist\n", 2), 1); if (ft_tablen(s) == 2 && access(s[1], X_OK) == 0) { set_env(env, "OLDPWD", getcwd(buf, 1024)); chdir(s[1]); set_env(env, "PWD", getcwd(buf, 1024)); return (1); } else if (ft_tablen(s) == 2 && access(s[1], X_OK) == -1) return (ft_putstr_fd("Access can not be granted\n", 2), 1); return (1); }
static int swsusp_pm_event(struct notifier_block *notifier, unsigned long pm_event, void *unused) { switch(pm_event) { case PM_HIBERNATION_PREPARE: /* Going to hibernate */ #ifdef CONFIG_MTK_SYSENV /* for lk */ set_env("hibboot", "1"); #endif return NOTIFY_DONE; case PM_POST_HIBERNATION: /* Hibernation finished */ #ifdef CONFIG_MTK_SYSENV /* from lk */ hib_log("hibboot = %s\n", get_env("hibboot")); set_env("hibboot", "0"); #endif return NOTIFY_DONE; } return NOTIFY_OK; }
static void init_misc () { // Test whether 'which' works #if defined(__MINGW__) || defined(__MINGW32__) || defined (OS_WIN32) use_which = false; #else use_which = (var_eval_system ("which texmacs 2> /dev/null") != ""); #endif //string loc= var_eval_system ("locate bin/locate 2> /dev/null"); //use_locate= (search_forwards ("bin/locate", loc) > 0); // Set extra environment variables for Cygwin #ifdef OS_CYGWIN set_env ("CYGWIN", "check_case:strict"); set_env ("COMSPEC", ""); set_env ("ComSpec", ""); #endif }