Sort the signature files
[Samba.git] / testsuite / nsswitch / getgrent_r.c
blob4f1f0ce8f5ec8fb34a297453990ca797d26e2b36
1 /*
2 * Use set/get/endgrent calls from two processes to iterate over the
3 * password database. This checks the multithreaded stuff works.
4 */
6 #include <stdio.h>
7 #include <grp.h>
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <fcntl.h>
11 #include <errno.h>
12 #include <wait.h>
14 void dump_grent(char *id)
16 struct group *gr;
17 char fname[255];
18 FILE *fptr;
20 /* Open results file */
22 sprintf(fname, "/tmp/getgrent_r-%s.out-%d", id, getpid());
24 if ((fptr = fopen(fname, "w")) == NULL) {
25 fprintf(stderr, "ERROR: could not open file %s: %s\n", fname,
26 sys_errlist[errno]);
27 return;
30 /* Dump group database */
32 setgrent();
34 while((gr = getgrent()) != NULL) {
35 fprintf(fptr,"%s:%s:%d:%d\n", gr->gr_name, gr->gr_passwd,
36 gr->gr_gid);
39 endgrent();
41 /* Close results file */
43 fclose(fptr);
46 int main(int argc, char **argv)
48 pid_t pid;
50 /* Check args */
52 if (argc != 2) {
53 printf("ERROR: must specify output file identifier\n");
54 return 1;
57 /* Fork child process */
59 if ((pid = fork()) == -1) {
60 printf("ERROR: unable to fork\n");
61 return 1;
64 /* Handle test case */
66 if (pid > 0) {
67 int status;
69 /* Parent */
71 dump_grent(argv[1]);
72 wait(&status);
74 } else {
76 /* Child */
78 dump_grent(argv[1]);
79 return 0;
82 printf("PASS: run getgrent_r.c\n");
83 return 0;