xref: /titanic_44/usr/src/ucbcmd/whoami/whoami.c (revision ea8dc4b6d2251b437950c0056bc626b311c73c27)
1 /*
2  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
7 /*	  All Rights Reserved  	*/
8 
9 /*
10  * Copyright (c) 1980 Regents of the University of California.
11  * All rights reserved.  The Berkeley software License Agreement
12  * specifies the terms and conditions for redistribution.
13  */
14 
15 #pragma ident	"%Z%%M%	%I%	%E% SMI"
16 
17 #include <unistd.h>
18 #include <sys/types.h>
19 #include <pwd.h>
20 #include <locale.h>
21 #include <stdlib.h>
22 
23 #define	MSG	"whoami: no login associated with uid %u.\n"
24 
25 /*
26  * whoami
27  */
28 
29 int
30 main(int argc, char *argv[])
31 /*ARGSUSED*/
32 {
33 	struct passwd *pp;
34 	uid_t	euid;
35 
36 	/* Set locale environment variables local definitions */
37 	(void) setlocale(LC_ALL, "");
38 #if	!defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
39 #define	TEXT_DOMAIN "SYS_TEST"  /* Use this only if it wasn't */
40 #endif
41 	(void) textdomain(TEXT_DOMAIN);
42 
43 	euid = geteuid();
44 	pp = getpwuid(euid);
45 	if (pp == 0) {
46 		(void) printf(gettext(MSG), euid);
47 		exit(1);
48 	}
49 	(void) printf("%s\n", pp->pw_name);
50 	return (0);
51 }
52