OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [linux/] [uClibc/] [test/] [pwd_grp/] [test_pwd.c] - Blame information for rev 1765

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/*
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.
9
 *
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.
14
 *
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.
18
 *
19
 */
20
 
21
#include <unistd.h>
22
#include <stdio.h>
23
#include <fcntl.h>
24
#include <pwd.h>
25
 
26
int main(int argc, char **argv)
27
{
28
        struct passwd *passwd;
29
        int test_uid;
30
 
31
        fprintf(stdout, "Beginning test of libc/pwd...\n");
32
 
33
        fprintf(stdout, "=> Testing setpwent(), getpwent(), endpwent()...\n");
34
        fprintf(stdout, "-> setpwent()...\n");
35
        setpwent();
36
        fprintf(stdout, "-> getpwent()...\n");
37
        printf
38
                ("********************************************************************************\n");
39
        while ((passwd = getpwent()) != NULL) {
40
                printf("pw_name\t\t: %s\n", passwd->pw_name);
41
                printf("pw_passwd\t: %s\n", passwd->pw_passwd);
42
                printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid);
43
                printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid);
44
                printf("pw_gecos\t: %s\n", passwd->pw_gecos);
45
                printf("pw_dir\t\t: %s\n", passwd->pw_dir);
46
                printf("pw_shell\t: %s\n", passwd->pw_shell);
47
                printf
48
                        ("********************************************************************************\n");
49
        }
50
        fprintf(stdout, "-> endpwent()...\n");
51
        endpwent();
52
        fprintf(stdout,
53
                        "=> Test of setpwent(), getpwent(), endpwent() complete.\n");
54
        fprintf(stdout, "=> Testing getpwuid(), getpwnam()...\n");
55
        fprintf(stdout, "-> getpwuid()...\n");
56
        printf
57
                ("********************************************************************************\n");
58
        for (test_uid = 0; test_uid < 1000; test_uid++) {
59
                fprintf(stdout, "-> getpwuid(%d)...\n", test_uid);
60
                passwd = getpwuid((uid_t) test_uid);
61
                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
70
                                ("********************************************************************************\n");
71
                }
72
        }
73
        fprintf(stdout, "-> getpwnam()...\n");
74
        passwd = getpwnam("root");
75
        if (passwd == NULL) {
76
                printf(">NULL<\n");
77
        } else {
78
                printf("pw_name\t\t: %s\n", passwd->pw_name);
79
                printf("pw_passwd\t: %s\n", passwd->pw_passwd);
80
                printf("pw_uid\t\t: %d\n", (int) passwd->pw_uid);
81
                printf("pw_gid\t\t: %d\n", (int) passwd->pw_gid);
82
                printf("pw_gecos\t: %s\n", passwd->pw_gecos);
83
                printf("pw_dir\t\t: %s\n", passwd->pw_dir);
84
                printf("pw_shell\t: %s\n", passwd->pw_shell);
85
        }
86
        return 0;
87
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.