Windows environment fix (buffer too small + handle return value)
This commit is contained in:
parent
7cf3b79840
commit
4ce2368c4f
1 changed files with 14 additions and 5 deletions
|
|
@ -352,14 +352,23 @@ R_API int r_sys_crash_handler(const char *cmd) {
|
|||
|
||||
R_API char *r_sys_getenv(const char *key) {
|
||||
#if __WINDOWS__ && !__CYGWIN__
|
||||
static char envbuf[1024];
|
||||
static char envbuf[4096];
|
||||
DWORD dwRet;
|
||||
|
||||
if (!key) {
|
||||
return NULL;
|
||||
}
|
||||
envbuf[0] = 0;
|
||||
GetEnvironmentVariableA (key, (LPSTR)&envbuf, sizeof (envbuf));
|
||||
// TODO: handle return value of GEV
|
||||
return *envbuf? strdup (envbuf): NULL;
|
||||
dwRet = GetEnvironmentVariableA (key, (LPSTR)&envbuf, sizeof (envbuf));
|
||||
if (dwRet == 0) {
|
||||
/* Variable not found. */
|
||||
return NULL;
|
||||
}
|
||||
if (dwRet == sizeof(envbuf)) {
|
||||
/* The contents of envbuf are undefined, so return NULL */
|
||||
eprintf ("Buffer too small to read `%s' environment variable.\n", key);
|
||||
return NULL;
|
||||
}
|
||||
return strdup (envbuf);
|
||||
#else
|
||||
char *b;
|
||||
if (!key) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue