|
Navigation
- Home
- Community
- Development
- myReactOS
- Fundraiser 2012
Doxygen
- Main Page
- Alphabetical List
- Data Structures
- Directories
- File List
- Data Fields
- Globals
- Related Pages
Search
|
|
|
Internal version of _wputenv and _putenv. It works duplicates the original envirnments created during initilization if needed to prevent having spurious pointers floating around. Then it updates the internal environment tables (_environ and _wenviron) and at last updates the OS environemnt.
Note that there can happen situation when the internal [_w]environ arrays will be updated, but the OS environment update will fail. In this case we don't undo the changes to the [_w]environ tables to comply with the Microsoft behaviour (and it's also much easier :-).
Definition at line 210 of file environ.c.
{
wchar_t *epos, *name;
wchar_t **wenvptr;
wchar_t *woption;
char *mboption;
int remove, index, count, size, result = 0, found = 0;
if (option == NULL || (epos = wcschr(option, L'=')) == NULL)
return -1;
remove = (epos[1] == 0);
if (_environ == __initenv)
{
if ((_environ = DuplicateEnvironment(_environ, 0)) == __initenv)
return -1;
}
if (_wenviron == __winitenv)
{
if ((_wenviron = (wchar_t**)DuplicateEnvironment((char**)_wenviron, 1)) ==
__winitenv)
return -1;
}
name = malloc((epos - option + 1) * sizeof(wchar_t));
if (name == NULL)
return -1;
memcpy(name, option, (epos - option) * sizeof(wchar_t));
name[epos - option] = 0;
for (index = 0, wenvptr = _wenviron; *wenvptr != NULL; wenvptr++, index++)
{
if (!_wcsnicmp(*wenvptr, option, epos - option))
{
found = 1;
break;
}
}
if (remove)
{
if (!found)
{
free(name);
return 0;
}
free(*wenvptr);
for (count = index; *wenvptr != NULL; wenvptr++, count++)
*wenvptr = *(wenvptr + 1);
_wenviron = realloc(_wenviron, count * sizeof(wchar_t*));
free(_environ[index]);
memmove(&_environ[index], &_environ[index+1], (count - index) * sizeof(char*));
_environ = realloc(_environ, count * sizeof(char*));
result = SetEnvironmentVariableW(name, NULL) ? 0 : -1;
}
else
{
woption = _wcsdup((wchar_t*)option);
if (woption == NULL)
{
free(name);
return -1;
}
size = WideCharToMultiByte(CP_ACP, 0, option, -1, NULL, 0, NULL, NULL);
mboption = malloc(size);
if (mboption == NULL)
{
free(name);
free(woption);
return -1;
}
WideCharToMultiByte(CP_ACP, 0, option, -1, mboption, size, NULL, NULL);
if (found)
{
free(*wenvptr);
*wenvptr = woption;
free(_environ[index]);
_environ[index] = mboption;
}
else
{
wchar_t **wnewenv;
char **mbnewenv;
for (count = index; *wenvptr != NULL; wenvptr++, count++)
;
if ((wnewenv = realloc(_wenviron, (count + 2) * sizeof(wchar_t*))) == NULL)
{
free(name);
free(mboption);
free(woption);
return -1;
}
_wenviron = wnewenv;
if ((mbnewenv = realloc(_environ, (count + 2) * sizeof(char*))) == NULL)
{
free(name);
free(mboption);
free(woption);
return -1;
}
_environ = mbnewenv;
_wenviron[count] = woption;
_environ[count] = mboption;
_wenviron[count + 1] = NULL;
_environ[count + 1] = NULL;
}
result = SetEnvironmentVariableW(name, epos + 1) ? 0 : -1;
}
free(name);
return result;
}
|
Generated on Mon May 28 2012 06:05:59 for ReactOS by
1.7.6.1
|