1
/* -*- buffer-read-only: t -*- vi: set ro: */
2
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
4
Copyright (C) 2009-2011 Free Software Foundation, Inc.
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.
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.
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/>. */
19
/* Written by Eric Blake <ebb9@byu.net>, 2009. */
25
#include "signature.h"
26
SIGNATURE_CHECK (getgroups, int, (int, gid_t[]));
36
main (int argc, char **argv _GL_UNUSED)
42
result = getgroups (0, NULL);
43
if (result == -1 && errno == ENOSYS)
45
fputs ("skipping test: no support for groups\n", stderr);
49
ASSERT (result + 1 < SIZE_MAX / sizeof *groups);
50
groups = malloc ((result + 1) * sizeof *groups);
53
/* Check for EINVAL handling. Not all processes have supplemental
54
groups, and getgroups does not have to return the effective gid,
55
so a result of 0 is reasonable. Also, we can't test for EINVAL
56
if result is 1, because of how getgroups treats 0. */
60
ASSERT (getgroups (result - 1, groups) == -1);
61
ASSERT (errno == EINVAL);
63
ASSERT (getgroups (result, groups) == result);
64
ASSERT (getgroups (result + 1, groups) == result);
65
ASSERT (groups[result] == -1);
67
ASSERT (getgroups (-1, NULL) == -1);
68
ASSERT (errno == EINVAL);
70
/* The automated unit test, with no arguments, ends here. However,
71
for debugging purposes, you can pass a command-line argument to
72
list the returned groups. */
76
for (i = 0; i < result; i++)
77
printf ("%d\n", (int) groups[i]);