1 /* Copyright (C) 1999-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
22 #include <sys/types.h>
28 write_users (FILE *f
, int large_pos
, int pos
)
35 fprintf (f
, ":three");
37 /* we need more than 2048 bytes for proper testing. */
38 for (i
= 0; i
< 500; i
++)
39 fprintf (f
, ",user%03d", i
);
46 write_group (const char *filename
, int pos
)
50 f
= fopen (filename
, "w");
51 fprintf (f
, "one:x:1:one");
52 write_users (f
, pos
, 1);
53 fprintf (f
, "two:x:2:two");
54 write_users (f
, pos
, 2);
55 fprintf (f
, "three:x:3");
56 write_users (f
, pos
, 3);
61 test_entry (const char *name
, gid_t gid
, struct group
*g
)
65 printf ("Error: Entry is empty\n");
70 if ((g
->gr_gid
== gid
) && (strcmp (g
->gr_name
, name
) == 0))
71 printf ("Ok: %s: %d\n", g
->gr_name
, g
->gr_gid
);
74 printf ("Error: %s: %d should be: %s: %d\n", g
->gr_name
, g
->gr_gid
,
82 test_fgetgrent (const char *filename
)
87 f
= fopen (filename
,"r");
90 test_entry ("one", 1, g
);
92 test_entry ("two", 2, g
);
94 test_entry ("three", 3, g
);
100 main (int argc
, char *argv
[])
102 char file
[] = "/tmp/tst_fgetgrent.XXXXXX";
103 int fd
= mkstemp (file
);
106 printf ("mkstemp failed: %m\n");
117 printf ("Large group is group: %d\n", i
);
119 printf ("Not using a large group\n");
120 write_group (file
, i
);
121 test_fgetgrent (file
);
125 return (errors
!= 0);