Eterm os_putenv_2(Process* p, Eterm key, Eterm value) { char def_buf[1024]; char *buf = NULL; int sep_ix, i, key_len, value_len, tot_len; key_len = is_string(key); if (!key_len) { error: if (buf) erts_free(ERTS_ALC_T_TMP, (void *) buf); BIF_ERROR(p, BADARG); } if (is_nil(value)) value_len = 0; else { value_len = is_string(value); if (!value_len) goto error; } tot_len = key_len + 1 + value_len + 1; if (tot_len <= sizeof(def_buf)) buf = &def_buf[0]; else buf = erts_alloc(ERTS_ALC_T_TMP, tot_len); i = intlist_to_buf(key, buf, key_len); if (i != key_len) erl_exit(1, "%s:%d: Internal error\n", __FILE__, __LINE__); sep_ix = i; buf[i++] = '='; if (is_not_nil(value)) i += intlist_to_buf(value, &buf[i], value_len); if (i != key_len + 1 + value_len) erl_exit(1, "%s:%d: Internal error\n", __FILE__, __LINE__); buf[i] = '\0'; if (erts_sys_putenv(buf, sep_ix)) { goto error; } if (buf != &def_buf[0]) erts_free(ERTS_ALC_T_TMP, (void *) buf); BIF_RET(am_true); }
BIF_RETTYPE os_putenv_2(BIF_ALIST_2) { char def_buf_key[STATIC_BUF_SIZE]; char def_buf_value[STATIC_BUF_SIZE]; char *key_buf, *value_buf; key_buf = erts_convert_filename_to_native(BIF_ARG_1,def_buf_key, STATIC_BUF_SIZE, ERTS_ALC_T_TMP,0,0,NULL); if (!key_buf) { BIF_ERROR(BIF_P, BADARG); } value_buf = erts_convert_filename_to_native(BIF_ARG_2,def_buf_value, STATIC_BUF_SIZE, ERTS_ALC_T_TMP,1,0, NULL); if (!value_buf) { if (key_buf != def_buf_key) { erts_free(ERTS_ALC_T_TMP, key_buf); } BIF_ERROR(BIF_P, BADARG); } if (erts_sys_putenv(key_buf, value_buf)) { if (key_buf != def_buf_key) { erts_free(ERTS_ALC_T_TMP, key_buf); } if (value_buf != def_buf_value) { erts_free(ERTS_ALC_T_TMP, value_buf); } BIF_ERROR(BIF_P, BADARG); } if (key_buf != def_buf_key) { erts_free(ERTS_ALC_T_TMP, key_buf); } if (value_buf != def_buf_value) { erts_free(ERTS_ALC_T_TMP, value_buf); } BIF_RET(am_true); }
int erts_sys_putenv_raw(char *key, char *value) { return erts_sys_putenv(key, value); }