This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include <unistd.h>
22
23 #include "signature.h"
24 SIGNATURE_CHECK (getgroups, int, (int, gid_t[]));
25
26 #include <errno.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <stdint.h>
30
31 #include "macros.h"
32
33
34
35
36
37
38 #if __GNUC__ >= 7
39 # pragma GCC diagnostic ignored "-Wstringop-overflow"
40 #endif
41
42 int
43 main (int argc, _GL_UNUSED char **argv)
44 {
45 int result;
46 gid_t *groups;
47
48 errno = 0;
49 result = getgroups (0, NULL);
50 if (result == -1 && errno == ENOSYS)
51 {
52 fputs ("skipping test: no support for groups\n", stderr);
53 return 77;
54 }
55 ASSERT (0 <= result);
56 ASSERT (result + 1 < SIZE_MAX / sizeof *groups);
57 groups = malloc ((result + 1) * sizeof *groups);
58 ASSERT (groups);
59 groups[result] = -1;
60
61
62
63
64 if (1 < result)
65 {
66 errno = 0;
67 ASSERT (getgroups (result - 1, groups) == -1);
68 ASSERT (errno == EINVAL);
69 }
70 ASSERT (getgroups (result, groups) == result);
71 ASSERT (getgroups (result + 1, groups) == result);
72 ASSERT (groups[result] == -1);
73 errno = 0;
74 ASSERT (getgroups (-1, NULL) == -1);
75 ASSERT (errno == EINVAL);
76
77
78
79
80 if (1 < argc)
81 {
82 int i;
83 for (i = 0; i < result; i++)
84 printf ("%d\n", (int) groups[i]);
85 }
86 free (groups);
87 return 0;
88 }