Пример #1
0
static WCHAR *
merge_environment(WCHAR *old, WCHAR *add)
{
    WCHAR **a_arg = env_to_arg(add);
    WCHAR **c_arg = env_to_arg(old);
    WCHAR *ret;
    int i, j;
    
    for(i = 0; c_arg[i] != NULL; ++i)
	;

    for(j = 0; a_arg[j] != NULL; ++j)
	;

    c_arg = erts_realloc(ERTS_ALC_T_TMP,
			 c_arg, (i+j+1) * sizeof(WCHAR *));

    for(j = 0; a_arg[j] != NULL; ++j){
	WCHAR **tmp;
	WCHAR *current = a_arg[j];
	WCHAR *eq_p = wcschr(current,L'=');
	int unset = (eq_p!=NULL && eq_p[1]==L'\0');

	if ((tmp = find_arg(c_arg, current)) != NULL) {
	    if (!unset) {
		*tmp = current;
	    } else {
		*tmp = c_arg[--i];
		c_arg[i] = NULL;
	    }
	} else if (!unset) {
	    c_arg[i++] = current;
	    c_arg[i] = NULL;
	}
    }
    ret = arg_to_env(c_arg);
    erts_free(ERTS_ALC_T_TMP, c_arg);
    erts_free(ERTS_ALC_T_TMP, a_arg);
    return ret;
}
Пример #2
0
static char*
merge_environment(char *old, char *add)
{
    char **a_arg = env_to_arg(add);
    char **c_arg = env_to_arg(old);
    char *ret;
    int i, j;
    
    for(i = 0; c_arg[i] != NULL; ++i)
	;

    for(j = 0; a_arg[j] != NULL; ++j)
	;

    c_arg = erts_realloc(ERTS_ALC_T_TMP,
			 c_arg, (i+j+1) * sizeof(char *));

    for(j = 0; a_arg[j] != NULL; ++j){
	char **tmp;
	char *current = a_arg[j];

	if ((tmp = find_arg(c_arg, current)) != NULL) {
	    if (current[strlen(current)-1] != '=') {
		*tmp = current;
	    } else {
		*tmp = c_arg[--i];
		c_arg[i] = NULL;
	    }
	} else if (current[strlen(current)-1] != '=') {
	    c_arg[i++] = current;
	    c_arg[i] = NULL;
	}
    }
    ret = arg_to_env(c_arg);
    erts_free(ERTS_ALC_T_TMP, c_arg);
    erts_free(ERTS_ALC_T_TMP, a_arg);
    return ret;
}
Пример #3
0
wchar_t *edit_env(wchar_t *edit, wchar_t *oldenv){
  wchar_t **arg;
  wchar_t *value;
  wchar_t *name = wcsdup(edit);
  int i;
  wchar_t *tmp;
  arg = env_to_arg(oldenv);
  value = wcschr(name,L'=');
  if(value){
    *(value++) = L'\0';
    if(*value == L'\0')
      value = NULL;
  }
  for(i=0;arg[i] != NULL; ++i){
    tmp = wcschr(arg[i],L'=');
    if(((int) wcslen(name)) == (tmp - arg[i]) &&
       !_wcsnicmp(name,arg[i], tmp - arg[i]))
      break;
  }
  if(arg[i] != NULL){
    free(arg[i]);
    if(value){
      arg[i] = wcsdup(edit);
    } else {
      do {
	arg[i] = arg[i+1];
	++i;
      } while(arg[i] != NULL);
    }
  } else if(value){ /* add to arg, which is always allocated
		     to hold one extra environment variable*/
    arg[i] = wcsdup(edit);
    arg[i+1] = NULL;
  }
  free(name);
  return arg_to_env(arg);
}