|
|
1.1 root 1: #include <stdio.h>
2: #include "stdefs.h"
3: #include <pwd.h>
4:
5: /* @(#)homedir.c 1.1 11/25/80 07:41:35
6: * Get home directory of designated user.
7: * If this program is compiled with the option "-DMAIN", then it will
8: * produce a main program that prints the result on standard output.
9: * otherwise it will produce a C-callable subroutine that returns a pointer
10: * to a static area containing the result.
11: * In either case, the user name is the argument to the procedure.
12: * J. Leth, IH 6E-318, x6133.
13: */
14:
15: /* Functions: */
16: extern struct passwd * getpwnam();
17:
18: #ifndef MAIN
19: char *
20: homedir(user)
21: char *user; /* user login name */
22: {
23:
24: #else
25: main(argc, argv)
26: int argc;
27: char *argv[];
28: {
29: char *user;
30: #endif
31:
32: struct passwd *pwentry;
33:
34: #ifdef MAIN
35: if (argc != 2) {
36: usage("Usage:\thomedir user\n\
37: Prints home directory (login dir.) of the designated user.\n");
38: }
39: user = argv[1];
40: #endif
41:
42: if((pwentry = getpwnam(user)) == NULL) {
43: errexit("homedir: user '%s' unknown.\n", user);
44: }
45:
46: #ifdef MAIN
47: puts(pwentry->pw_dir);
48: #else
49: return(pwentry->pw_dir);
50: #endif
51: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.