Support binutils 2.100 and 3.0.
[glibc.git] / gshadow / tst-gshadow.c
blob8b469b723d1aecf80b0317996533c229463804d0
1 #include <gshadow.h>
2 #include <stdio.h>
3 #include <string.h>
6 static const struct sgrp data[] =
8 { (char *) "one", (char *) "pwdone",
9 (char *[]) { (char *) "admoneone", (char *) "admonetwo",
10 (char *) "admonethree", NULL },
11 (char *[]) { (char *) "memoneone", (char *) "memonetwo",
12 (char *) "memonethree", NULL } },
13 { (char *) "two", (char *) "pwdtwo",
14 (char *[]) { (char *) "admtwoone", (char *) "admtwotwo", NULL },
15 (char *[]) { (char *) "memtwoone", (char *) "memtwotwo",
16 (char *) "memtwothree", NULL } },
17 { (char *) "three", (char *) "pwdthree",
18 (char *[]) { (char *) "admthreeone", (char *) "admthreetwo", NULL },
19 (char *[]) { (char *) "memthreeone", (char *) "memthreetwo", NULL } },
20 { (char *) "four", (char *) "pwdfour",
21 (char *[]) { (char *) "admfourone", (char *) "admfourtwo", NULL },
22 (char *[]) { NULL } },
23 { (char *) "five", (char *) "pwdfive",
24 (char *[]) { NULL },
25 (char *[]) { (char *) "memfiveone", (char *) "memfivetwo", NULL } },
27 #define ndata (sizeof (data) / sizeof (data[0]))
30 static int
31 do_test (void)
33 FILE *fp = tmpfile ();
34 if (fp == NULL)
36 puts ("cannot open temporary file");
37 return 1;
40 for (size_t i = 0; i < ndata; ++i)
41 if (putsgent (&data[i], fp) != 0)
43 printf ("putsgent call %zu failed\n", i + 1);
44 return 1;
47 rewind (fp);
49 int result = 0;
50 int seen = -1;
51 struct sgrp *g;
52 while ((g = fgetsgent (fp)) != NULL)
54 ++seen;
55 if (strcmp (g->sg_namp, data[seen].sg_namp) != 0)
57 printf ("sg_namp of entry %d does not match: %s vs %s\n",
58 seen + 1, g->sg_namp, data[seen].sg_namp);
59 result = 1;
61 if (strcmp (g->sg_passwd, data[seen].sg_passwd) != 0)
63 printf ("sg_passwd of entry %d does not match: %s vs %s\n",
64 seen + 1, g->sg_passwd, data[seen].sg_passwd);
65 result = 1;
67 if (g->sg_adm == NULL)
69 printf ("sg_adm of entry %d is NULL\n", seen + 1);
70 result = 1;
72 else
74 int i = 1;
75 char **sp1 = g->sg_adm;
76 char **sp2 = data[seen].sg_adm;
77 while (*sp1 != NULL && *sp2 != NULL)
79 if (strcmp (*sp1, *sp2) != 0)
81 printf ("sg_adm[%d] of entry %d does not match: %s vs %s\n",
82 i, seen + 1, *sp1, *sp2);
83 result = 1;
85 ++sp1;
86 ++sp2;
87 ++i;
89 if (*sp1 == NULL && *sp2 != NULL)
91 printf ("sg_adm of entry %d has too few entries\n", seen + 1);
92 result = 1;
94 else if (*sp1 != NULL && *sp2 == NULL)
96 printf ("sg_adm of entry %d has too many entries\n", seen + 1);
97 result = 1;
100 if (g->sg_mem == NULL)
102 printf ("sg_mem of entry %d is NULL\n", seen + 1);
103 result = 1;
105 else
107 int i = 1;
108 char **sp1 = g->sg_mem;
109 char **sp2 = data[seen].sg_mem;
110 while (*sp1 != NULL && *sp2 != NULL)
112 if (strcmp (*sp1, *sp2) != 0)
114 printf ("sg_mem[%d] of entry %d does not match: %s vs %s\n",
115 i, seen + 1, *sp1, *sp2);
116 result = 1;
118 ++sp1;
119 ++sp2;
120 ++i;
122 if (*sp1 == NULL && *sp2 != NULL)
124 printf ("sg_mem of entry %d has too few entries\n", seen + 1);
125 result = 1;
127 else if (*sp1 != NULL && *sp2 == NULL)
129 printf ("sg_mem of entry %d has too many entries\n", seen + 1);
130 result = 1;
135 fclose (fp);
137 return result;
140 #define TEST_FUNCTION do_test ()
141 #include "../test-skeleton.c"