xref: /original-bsd/old/whoami/whoami.c (revision f25de740)
1 /*
2  * Copyright (c) 1988 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12 
13 #ifndef lint
14 char copyright[] =
15 "@(#) Copyright (c) 1988 Regents of the University of California.\n\
16  All rights reserved.\n";
17 #endif /* not lint */
18 
19 #ifndef lint
20 static char sccsid[] = "@(#)whoami.c	5.2 (Berkeley) 06/09/88";
21 #endif /* not lint */
22 
23 #include <sys/types.h>
24 #include <pwd.h>
25 
26 main()
27 {
28 	struct passwd *p, *getpwuid();
29 	uid_t uid;
30 
31 	uid = geteuid();
32 	if (!(p = getpwuid(uid))) {
33 		printf("whoami: no login associated with uid %u.\n", uid);
34 		exit(1);
35 	}
36 	printf("%s\n", p->pw_name);
37 	exit(0);
38 }
39