mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 01:24:38 +00:00
Removed fixed size of environment vars.
svn path=/trunk/; revision=2805
This commit is contained in:
parent
2cda2c03b3
commit
ae374594ce
2 changed files with 42 additions and 21 deletions
|
@ -1,23 +1,35 @@
|
|||
#include <windows.h>
|
||||
#include <msvcrt/stdlib.h>
|
||||
|
||||
#define NDEBUG
|
||||
#include <msvcrt/msvcrtdbg.h>
|
||||
|
||||
|
||||
char *getenv(const char *name)
|
||||
{
|
||||
char *buffer;
|
||||
buffer = (char *)malloc(MAX_PATH);
|
||||
buffer[0] = 0;
|
||||
if ( GetEnvironmentVariableA(name,buffer,MAX_PATH) == 0 )
|
||||
char *buffer = (char*)0xffffffff;
|
||||
int len = GetEnvironmentVariableA(name,buffer,0) + 1;
|
||||
DPRINT("getenv(%s)\n", name);
|
||||
buffer = (char *)malloc(len);
|
||||
DPRINT("getenv('%s') %d %x\n", name, len, buffer);
|
||||
if (buffer == NULL || GetEnvironmentVariableA(name,buffer,len) == 0 )
|
||||
{
|
||||
free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
wchar_t *_wgetenv(const wchar_t *name)
|
||||
{
|
||||
wchar_t *buffer;
|
||||
buffer = (wchar_t *)malloc(MAX_PATH * sizeof(wchar_t));
|
||||
buffer[0] = 0;
|
||||
if ( GetEnvironmentVariableW(name,buffer,MAX_PATH) == 0 )
|
||||
wchar_t *buffer = (wchar_t*)0xffffffff;
|
||||
int len = GetEnvironmentVariableW(name, buffer,0) + 1;
|
||||
DPRINT("_wgetenv(%S)\n", name);
|
||||
buffer = (wchar_t *)malloc(len * sizeof(wchar_t));
|
||||
if (buffer == NULL || GetEnvironmentVariableW(name,buffer,len) == 0)
|
||||
{
|
||||
free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
|
|
@ -2,41 +2,50 @@
|
|||
#include <msvcrt/stdlib.h>
|
||||
#include <msvcrt/string.h>
|
||||
|
||||
#define NDEBUG
|
||||
#include <msvcrt/msvcrtdbg.h>
|
||||
|
||||
|
||||
extern int BlockEnvToEnviron(); // defined in misc/dllmain.c
|
||||
|
||||
int _putenv(const char *val)
|
||||
{
|
||||
char buffer[1024];
|
||||
char *buffer;
|
||||
char *epos;
|
||||
int res;
|
||||
|
||||
strcpy(buffer,val);
|
||||
epos = strchr(buffer, '=');
|
||||
DPRINT("_putenv('%s')\n", val);
|
||||
epos = strchr(val, '=');
|
||||
if ( epos == NULL )
|
||||
return -1;
|
||||
|
||||
*epos = 0;
|
||||
|
||||
buffer = (char*)malloc(epos - val + 1);
|
||||
if (buffer == NULL)
|
||||
return -1;
|
||||
strncpy(buffer, val, epos - val);
|
||||
buffer[epos - val] = 0;
|
||||
res = SetEnvironmentVariableA(buffer,epos+1);
|
||||
if (BlockEnvToEnviron() ) return 0;
|
||||
free(buffer);
|
||||
if (BlockEnvToEnviron()) return 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
int _wputenv(const wchar_t *val)
|
||||
{
|
||||
wchar_t buffer[1024];
|
||||
wchar_t *buffer;
|
||||
wchar_t *epos;
|
||||
int res;
|
||||
|
||||
wcscpy(buffer,val);
|
||||
epos = wcschr(buffer, L'=');
|
||||
DPRINT("_wputenv('%S')\n", val);
|
||||
epos = wcsrchr(val, L'=');
|
||||
if ( epos == NULL )
|
||||
return -1;
|
||||
|
||||
*epos = 0;
|
||||
|
||||
buffer = (char*)malloc((epos - val + 1) * sizeof (wchar_t));
|
||||
if (buffer == NULL)
|
||||
return -1;
|
||||
wcsncpy(buffer, val, epos - val);
|
||||
buffer[epos - val] = 0;
|
||||
res = SetEnvironmentVariableW(buffer,epos+1);
|
||||
free(buffer);
|
||||
if (BlockEnvToEnviron() ) return 0;
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue