s3:winbindd: make use of samba_tevent_context_init()
[Samba/gebeck_regimport.git] / tests / getgroups.c
blob343fd5a184f908e0c3d5686f249f76e4de674533
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 #if defined(HAVE_UNISTD_H)
11 #include <unistd.h>
12 #endif
14 #include <sys/types.h>
15 #include <stdio.h>
16 #include <unistd.h>
17 #include <grp.h>
19 main()
21 int i;
22 int *igroups;
23 char *cgroups;
24 int grp = 0;
25 int ngroups = getgroups(0,&grp);
27 if (sizeof(gid_t) == sizeof(int)) {
28 fprintf(stderr,"gid_t and int are the same size\n");
29 exit(1);
32 if (ngroups <= 0)
33 ngroups = 32;
35 igroups = (int *)malloc(sizeof(int)*ngroups);
37 for (i=0;i<ngroups;i++)
38 igroups[i] = 0x42424242;
40 ngroups = getgroups(ngroups,(gid_t *)igroups);
42 if (igroups[0] == 0x42424242)
43 ngroups = 0;
45 if (ngroups == 0) {
46 printf("WARNING: can't determine getgroups return type\n");
47 exit(1);
50 cgroups = (char *)igroups;
52 if (ngroups == 1 &&
53 cgroups[2] == 0x42 && cgroups[3] == 0x42) {
54 fprintf(stderr,"getgroups returns gid_t\n");
55 exit(1);
58 for (i=0;i<ngroups;i++) {
59 if (igroups[i] == 0x42424242) {
60 fprintf(stderr,"getgroups returns gid_t\n");
61 exit(1);
65 exit(0);