summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorWilliam A. Rowe Jr <wrowe@apache.org>2006-11-06 21:05:26 +0000
committerWilliam A. Rowe Jr <wrowe@apache.org>2006-11-06 21:05:26 +0000
commitc530a22ad6bfd560cf20ae5ced5ec8af42a15e79 (patch)
treec636e5cd259cf39561b837c189628f7a7e71e144 /misc
parent49e1dd5b81f2f260550beb20f72697843d6add9a (diff)
downloadapr-c530a22ad6bfd560cf20ae5ced5ec8af42a15e79.tar.gz
Correctly retrieve 'empty' environment values with apr_env_get
on Win32 (e.g. "VAR="), and added validation to testall suite. PR: 40764 Submitted by: Issac Goldstand <margol beamartyr.net> Reviewed by: wrowe git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@471877 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'misc')
-rw-r--r--misc/win32/env.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/misc/win32/env.c b/misc/win32/env.c
index 5c998643f..e99ff8d47 100644
--- a/misc/win32/env.c
+++ b/misc/win32/env.c
@@ -22,6 +22,7 @@
#include "apr_env.h"
#include "apr_errno.h"
#include "apr_pools.h"
+#include "apr_strings.h"
#if APR_HAS_UNICODE_FS
@@ -61,11 +62,18 @@ APR_DECLARE(apr_status_t) apr_env_get(char **value,
if (status)
return status;
+ SetLastError(0);
size = GetEnvironmentVariableW(wenvvar, &dummy, 0);
- if (size == 0)
+ if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
/* The environment variable doesn't exist. */
return APR_ENOENT;
+ if (size == 0) {
+ /* The environment value exists, but is zero-length. */
+ *value = apr_pstrdup(pool, "");
+ return APR_SUCCESS;
+ }
+
wvalue = apr_palloc(pool, size * sizeof(*wvalue));
size = GetEnvironmentVariableW(wenvvar, wvalue, size);
if (size == 0)
@@ -85,11 +93,18 @@ APR_DECLARE(apr_status_t) apr_env_get(char **value,
{
char dummy;
+ SetLastError(0);
size = GetEnvironmentVariableA(envvar, &dummy, 0);
- if (size == 0)
+ if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
/* The environment variable doesn't exist. */
return APR_ENOENT;
+ if (size == 0) {
+ /* The environment value exists, but is zero-length. */
+ *value = apr_pstrdup(pool, "");
+ return APR_SUCCESS;
+ }
+
val = apr_palloc(pool, size);
size = GetEnvironmentVariableA(envvar, val, size);
if (size == 0)