From ad4a00d35ab45fabd4076dc10c5010dca59cc54c Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Mon, 19 Jul 2004 21:23:02 +0000 Subject: [PATCH] Add some test cases for _wputenv, fix deletion of non-existent environment variables, return -1 on error. --- dlls/msvcrt/environ.c | 12 ++++++++++-- dlls/msvcrt/tests/.cvsignore | 1 + dlls/msvcrt/tests/Makefile.in | 1 + dlls/msvcrt/tests/environ.c | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 dlls/msvcrt/tests/environ.c diff --git a/dlls/msvcrt/environ.c b/dlls/msvcrt/environ.c index 78bf32c81b..e8630007fb 100644 --- a/dlls/msvcrt/environ.c +++ b/dlls/msvcrt/environ.c @@ -91,7 +91,11 @@ int _putenv(const char *str) *dst++ = *str++; *dst = '\0'; - ret = !SetEnvironmentVariableA(name, value[0] ? value : NULL); + ret = SetEnvironmentVariableA(name, value[0] ? value : NULL) ? 0 : -1; + + /* _putenv returns success on deletion of non-existent variable, unlike [Rtl]SetEnvironmentVariable */ + if ((ret == -1) && (GetLastError() == ERROR_ENVVAR_NOT_FOUND)) ret = 0; + /* Update the __p__environ array only when already initialized */ if (_environ) _environ = msvcrt_SnapshotOfEnvironmentA(_environ); @@ -123,7 +127,11 @@ int _wputenv(const MSVCRT_wchar_t *str) *dst++ = *str++; *dst = 0; - ret = !SetEnvironmentVariableW(name, value[0] ? value : NULL); + ret = SetEnvironmentVariableW(name, value[0] ? value : NULL) ? 0 : -1; + + /* _putenv returns success on deletion of non-existent variable, unlike [Rtl]SetEnvironmentVariable */ + if ((ret == -1) && (GetLastError() == ERROR_ENVVAR_NOT_FOUND)) ret = 0; + /* Update the __p__environ array only when already initialized */ if (_environ) _environ = msvcrt_SnapshotOfEnvironmentA(_environ); diff --git a/dlls/msvcrt/tests/.cvsignore b/dlls/msvcrt/tests/.cvsignore index bd56b02a4f..4eac978520 100644 --- a/dlls/msvcrt/tests/.cvsignore +++ b/dlls/msvcrt/tests/.cvsignore @@ -1,5 +1,6 @@ Makefile cpp.ok +environ.ok file.ok headers.ok heap.ok diff --git a/dlls/msvcrt/tests/Makefile.in b/dlls/msvcrt/tests/Makefile.in index 785a37cc15..1af0d6735c 100644 --- a/dlls/msvcrt/tests/Makefile.in +++ b/dlls/msvcrt/tests/Makefile.in @@ -8,6 +8,7 @@ EXTRAINCL = -I$(TOPSRCDIR)/include/msvcrt -I$(SRCDIR)/.. CTESTS = \ cpp.c \ + environ.c \ file.c \ headers.c \ heap.c \ diff --git a/dlls/msvcrt/tests/environ.c b/dlls/msvcrt/tests/environ.c new file mode 100644 index 0000000000..2197b5a8ed --- /dev/null +++ b/dlls/msvcrt/tests/environ.c @@ -0,0 +1,35 @@ +/* + * Unit tests for C library environment routines + * + * Copyright 2004 Mike Hearn + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "wine/test.h" +#include + +START_TEST(environ) +{ + ok( _putenv("cat=") == 0, "_putenv failed on deletion of non-existent environment variable\n" ); + ok( _putenv("cat=dog") == 0, "failed setting cat=dog\n" ); + ok( strcmp(getenv("cat"), "dog") == 0, "getenv did not return 'dog'\n" ); + ok( _putenv("cat=") == 0, "failed deleting cat\n" ); + + ok( _putenv("=") == -1, "should not accept '=' as input\n" ); + ok( _putenv("=dog") == -1, "should not accept '=dog' as input\n" ); + + ok( getenv("nonexistent") == NULL, "getenv should fail with nonexistent var name\n" ); +} -- 2.32.0.93.g670b81a890