Commit | Line | Data |
---|---|---|
f42904bc | 1 | /* |
1ba96f46 KB |
2 | * Copyright (c) 1988 Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
32ce521f | 5 | * %sccs.include.redist.c% |
f42904bc DF |
6 | */ |
7 | ||
8 | #ifndef lint | |
9 | char copyright[] = | |
1ba96f46 | 10 | "@(#) Copyright (c) 1988 Regents of the University of California.\n\ |
f42904bc | 11 | All rights reserved.\n"; |
1ba96f46 | 12 | #endif /* not lint */ |
f42904bc DF |
13 | |
14 | #ifndef lint | |
32ce521f | 15 | static char sccsid[] = "@(#)whoami.c 5.4 (Berkeley) %G%"; |
1ba96f46 | 16 | #endif /* not lint */ |
f42904bc | 17 | |
1ba96f46 | 18 | #include <sys/types.h> |
a309c47b | 19 | #include <pwd.h> |
a309c47b BJ |
20 | |
21 | main() | |
22 | { | |
1ba96f46 KB |
23 | struct passwd *p, *getpwuid(); |
24 | uid_t uid; | |
a309c47b | 25 | |
1ba96f46 KB |
26 | uid = geteuid(); |
27 | if (!(p = getpwuid(uid))) { | |
28 | printf("whoami: no login associated with uid %u.\n", uid); | |
a309c47b BJ |
29 | exit(1); |
30 | } | |
1ba96f46 | 31 | printf("%s\n", p->pw_name); |
a309c47b BJ |
32 | exit(0); |
33 | } |