1 /* Test the putenv function.
2 Copyright (C) 2024 Free Software Foundation, Inc.
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published
6 by the Free Software Foundation, either version 3 of the License,
7 or (at your option) any later version.
9 This file is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Collin Funk <collin.funk1@gmail.com>, 2024. */
24 #include "signature.h"
25 SIGNATURE_CHECK (putenv
, int, (char *));
36 /* Verify the environment is clean. */
37 unsetenv ("TEST_VAR");
38 ASSERT (getenv ("TEST_VAR") == NULL
);
40 /* Use static on variables passed to the environment to pacify
41 -Wanalyzer-putenv-of-auto-var. */
43 /* Verify adding an environment variable. */
45 static char var
[] = "TEST_VAR=abc";
46 ASSERT (putenv (var
) == 0);
47 ptr
= getenv ("TEST_VAR");
49 ASSERT (STREQ (ptr
, "abc"));
52 /* Verify removing an environment variable. */
54 static char var
[] = "TEST_VAR";
55 ASSERT (putenv (var
) == 0);
56 ASSERT (getenv ("TEST_VAR") == NULL
);
59 /* Verify the behavior when removing a variable not in the environment. */
61 static char var
[] = "TEST_VAR";
62 ASSERT (putenv (var
) == 0);
63 ASSERT (getenv ("TEST_VAR") == NULL
);
66 return test_exit_status
;