Ticket #6706: test-unsetenv.c

File test-unsetenv.c, 2.0 KB (added by scottmc, 14 years ago)
Line 
1/* -*- buffer-read-only: t -*- vi: set ro: */
2/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3/* Tests of unsetenv.
4 Copyright (C) 2009, 2010 Free Software Foundation, Inc.
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19/* Written by Eric Blake <ebb9@byu.net>, 2009. */
20
21#include <stdlib.h>
22
23#include <errno.h>
24#include <string.h>
25#include <unistd.h>
26#include <stdio.h>
27
28#define ASSERT(expr) \
29 do \
30 { \
31 if (!(expr)) \
32 { \
33 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
34 abort (); \
35 } \
36 } \
37 while (0)
38
39int
40main (void)
41{
42 char entry[] = "b=2";
43
44 /* Test removal when multiple entries present. */
45 ASSERT (putenv ((char *) "a=1") == 0);
46 ASSERT (putenv (entry) == 0);
47 entry[0] = 'a'; /* Unspecified what getenv("a") would be at this point. */
48 ASSERT (unsetenv ("a") == 0); /* Both entries will be removed. */
49 ASSERT (getenv ("a") == NULL);
50 ASSERT (unsetenv ("a") == 0);
51
52 /* Required to fail with EINVAL. */
53 errno = 0;
54 ASSERT (unsetenv ("") == -1);
55 ASSERT (errno == EINVAL);
56 errno = 0;
57 ASSERT (unsetenv ("a=b") == -1);
58 ASSERT (errno == EINVAL);
59#if 0
60 /* glibc and gnulib's implementation guarantee this, but POSIX no
61 longer requires it: http://austingroupbugs.net/view.php?id=185 */
62 errno = 0;
63 ASSERT (unsetenv (NULL) == -1);
64 ASSERT (errno == EINVAL);
65#endif
66
67 return 0;
68}