get rid of the runtime test for broken getgroups() and add a compile
[Samba/gbeck.git] / source / tests / getgroups.c
blob37990e010b8db159953ab1fac680bc946aee8127
1 /* this tests whether getgroups actually returns lists of integers
2 rather than gid_t. The test only works if the user running
3 the test is in at least 1 group
5 The test is designed to check for those broken OSes that define
6 getgroups() as returning an array of gid_t but actually return a
7 array of ints! Ultrix is one culprit
8 */
10 #include <sys/types.h>
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <grp.h>
15 main()
17 int i;
18 int *igroups;
19 char *cgroups;
20 int grp = 0;
21 int ngroups = getgroups(0,&grp);
23 if (sizeof(gid_t) == sizeof(int)) {
24 fprintf(stderr,"gid_t and int are the same size\n");
25 exit(1);
28 if (ngroups <= 0)
29 ngroups = 32;
31 igroups = (int *)malloc(sizeof(int)*ngroups);
33 for (i=0;i<ngroups;i++)
34 igroups[i] = 0x42424242;
36 ngroups = getgroups(ngroups,(gid_t *)igroups);
38 if (igroups[0] == 0x42424242)
39 ngroups = 0;
41 if (ngroups == 0) {
42 printf("WARNING: can't determine getgroups return type\n");
43 exit(1);
46 cgroups = (char *)igroups;
48 if (ngroups == 1 &&
49 cgroups[2] == 0x42 && cgroups[3] == 0x42) {
50 fprintf(stderr,"getgroups returns gid_t\n");
51 exit(1);
54 for (i=0;i<ngroups;i++) {
55 if (igroups[i] == 0x42424242) {
56 fprintf(stderr,"getgroups returns gid_t\n");
57 exit(1);
61 exit(0);