* tiny
[mascara-docs.git] / compilers / bcc / linux86-0.16.17 / libc / getent / test_pwd.c
blob74f7657a63e9db7e256449333b0da183ad0ded74
1 /*
2 * test_pwd.c - This file is part of the libc-8086/pwd package for ELKS,
3 * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <unistd.h>
22 #include <stdio.h>
23 #include <fcntl.h>
24 #include <pwd.h>
26 int
27 main(int argc, char ** argv)
29 struct passwd * passwd;
30 int test_uid;
32 fprintf(stderr, "Beginning test of libc/pwd...\n");
34 fprintf(stderr, "=> Testing setpwent(), getpwent(), endpwent()...\n");
35 fprintf(stderr, "-> setpwent()...\n");
36 setpwent();
37 fprintf(stderr, "-> getpwent()...\n");
38 printf("********************************************************************************\n");
39 while ((passwd=getpwent())!=NULL)
41 printf("pw_name\t\t: %s\n", passwd->pw_name);
42 printf("pw_passwd\t: %s\n", passwd->pw_passwd);
43 printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid);
44 printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid);
45 printf("pw_gecos\t: %s\n", passwd->pw_gecos);
46 printf("pw_dir\t\t: %s\n", passwd->pw_dir);
47 printf("pw_shell\t: %s\n", passwd->pw_shell);
48 printf("********************************************************************************\n");
50 fprintf(stderr, "-> endpwent()...\n");
51 endpwent();
52 fprintf(stderr, "=> Test of setpwent(), getpwent(), endpwent() complete.\n");
53 fprintf(stderr, "=> Testing getpwuid(), getpwnam()...\n");
54 fprintf(stderr, "-> getpwuid()...\n");
55 printf("********************************************************************************\n");
56 for(test_uid=0;test_uid<1000;test_uid++)
58 fprintf(stderr, "-> getpwuid(%d)...\n", test_uid);
59 passwd=getpwuid((uid_t) test_uid);
60 if (passwd!=NULL)
62 printf("pw_name\t\t: %s\n", passwd->pw_name);
63 printf("pw_passwd\t: %s\n", passwd->pw_passwd);
64 printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid);
65 printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid);
66 printf("pw_gecos\t: %s\n", passwd->pw_gecos);
67 printf("pw_dir\t\t: %s\n", passwd->pw_dir);
68 printf("pw_shell\t: %s\n", passwd->pw_shell);
69 printf("********************************************************************************\n");
72 fprintf(stderr, "-> getpwnam()...\n");
73 passwd=getpwnam("root");
74 if (passwd==NULL)
76 printf(">NULL<\n");
78 else
80 printf("pw_name\t\t: %s\n", passwd->pw_name);
81 printf("pw_passwd\t: %s\n", passwd->pw_passwd);
82 printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid);
83 printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid);
84 printf("pw_gecos\t: %s\n", passwd->pw_gecos);
85 printf("pw_dir\t\t: %s\n", passwd->pw_dir);
86 printf("pw_shell\t: %s\n", passwd->pw_shell);
88 return 0;