static VALUE env_aset(VALUE obj, SEL sel, VALUE nm, VALUE val) { if (rb_safe_level() >= 4) { rb_raise(rb_eSecurityError, "can't change environment variable"); } if (NIL_P(val)) { env_delete(obj, nm); return Qnil; } StringValue(nm); StringValue(val); const char *name = RSTRING_PTR(nm); const char *value = RSTRING_PTR(val); if (strlen(name) != RSTRING_LEN(nm)) { rb_raise(rb_eArgError, "bad environment variable name"); } if (strlen(value) != RSTRING_LEN(val)) { rb_raise(rb_eArgError, "bad environment variable value"); } ruby_setenv(name, value); if (strcmp(name, PATH_ENV) == 0) { if (OBJ_TAINTED(val)) { /* already tainted, no check */ path_tainted = 1; return val; } else { path_tainted_p(value); } } return val; }
static VALUE env_delete_m(VALUE obj, SEL sel, VALUE name) { VALUE val = env_delete(obj, name); if (NIL_P(val) && rb_block_given_p()) { rb_yield(name); } return val; }
static VALUE rb_env_clear_imp(VALUE rcv, SEL sel) { VALUE keys = env_keys(Qnil, 0); /* rb_secure(4); */ for (long i = 0, count = RARRAY_LEN(keys); i < count; i++) { VALUE val = rb_f_getenv(Qnil, 0, RARRAY_AT(keys, i)); if (!NIL_P(val)) { env_delete(Qnil, RARRAY_AT(keys, i)); } } return envtbl; }
int env_insert(const char* key, const char *value) { int klen = strlen(key) + 1; int vlen = strlen(value) + 1; if (klen + vlen >= (current_env_size - current_env->occupied)) return -1; /* No space */ env_delete(key); memcpy(¤t_env->data[current_env->occupied], key, klen); current_env->occupied+=klen; memcpy(¤t_env->data[current_env->occupied], value, vlen); current_env->occupied+=vlen; current_env->data[current_env->occupied]=0xff; return 0; }
static VALUE env_replace(VALUE env, SEL sel, VALUE hash) { VALUE keys = env_keys(Qnil, 0); /* rb_secure(4); */ if (env == hash) { return env; } hash = to_hash(hash); rb_hash_foreach(hash, env_replace_i, keys); for (long i = 0, count = RARRAY_LEN(keys); i < count; i++) { env_delete(env, RARRAY_AT(keys, i)); } return env; }
static int do_setenv(int argc, const char* const* argv) { switch (argc) { case 1: env_dump(); break; case 2: env_delete(argv[1]); break; case 3: env_insert(argv[1], argv[2]); break; } return 0; }
static VALUE env_shift(VALUE rcv, SEL sel) { rb_secure(4); char **env = GET_ENVIRON(); if (*env != NULL) { const char *s = strchr(*env, '='); if (s != NULL) { VALUE key = env_str_new(*env, s - *env); VALUE val = env_str_new2(getenv(RSTRING_PTR(key))); env_delete(Qnil, key); return rb_assoc_new(key, val); } } return Qnil; }
static VALUE env_reject_bang(VALUE ehash, SEL sel) { RETURN_ENUMERATOR(ehash, 0, 0); VALUE keys = env_keys(Qnil, 0); /* rb_secure(4); */ bool deleted = false; for (long i = 0, count = RARRAY_LEN(keys); i < count; i++) { VALUE key = RARRAY_AT(keys, i); VALUE val = rb_f_getenv(Qnil, 0, key); if (!NIL_P(val)) { VALUE v = rb_yield_values(2, key, val); RETURN_IF_BROKEN(); if (RTEST(v)) { rb_obj_untaint(key); env_delete(Qnil, key); deleted = true; } } } return deleted ? envtbl : Qnil; }
int ft_unset_env(char **args) { t_env *temp; t_env **env; int i; int size; env = ft_getenv(); i = 1; while (args[i]) { temp = *env; while (temp) { size = st_search_equal(temp->name); if (!ft_strncmp(temp->name, args[i], size)) env_delete(env, temp); if (temp) temp = temp->next; } i++; } return (1); }