Commit | Line | Data |
---|---|---|
c9656c75 KB |
1 | /*- |
2 | * Copyright (c) 1991 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * %sccs.include.redist.c% | |
6 | */ | |
7 | ||
8 | #ifndef lint | |
9 | char copyright[] = | |
10 | "@(#) Copyright (c) 1991 The Regents of the University of California.\n\ | |
11 | All rights reserved.\n"; | |
12 | #endif /* not lint */ | |
13 | ||
14 | #ifndef lint | |
15 | static char sccsid[] = "@(#)logname.c 5.1 (Berkeley) %G%"; | |
16 | #endif /* not lint */ | |
17 | ||
18 | #include <errno.h> | |
19 | #include <unistd.h> | |
20 | #include <stdio.h> | |
21 | #include <stdlib.h> | |
22 | #include <string.h> | |
23 | ||
24 | main(argc, argv) | |
25 | int argc; | |
26 | char *argv[]; | |
27 | { | |
28 | int ch; | |
29 | char *p; | |
30 | ||
31 | while ((ch = getopt(argc, argv, "")) != EOF) | |
32 | switch(ch) { | |
33 | case '?': | |
34 | default: | |
35 | usage(); | |
36 | } | |
37 | argc -= optind; | |
38 | argv += optind; | |
39 | ||
40 | if ((p = getlogin()) == NULL) { | |
41 | (void)fprintf(stderr, "logname: %s\n", strerror(errno)); | |
42 | exit(1); | |
43 | } | |
44 | (void)printf("%s\n", p); | |
45 | exit(0); | |
46 | } | |
47 | ||
48 | usage() | |
49 | { | |
50 | (void)fprintf(stderr, "usage: logname\n"); | |
51 | exit(1); | |
52 | } |