xref: /illumos-gate/usr/src/ucbcmd/whoami/whoami.c (revision 42b53e0fbc5c05289c3d334bb864b784fafe5ce4)
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 #include <unistd.h>
16 #include <sys/types.h>
17 #include <pwd.h>
18 #include <locale.h>
19 #include <stdlib.h>
20 
21 #define	MSG	"whoami: no login associated with uid %u.\n"
22 
23 /*
24  * whoami
25  */
26 
27 int
28 main(int argc, char *argv[])
29 /*ARGSUSED*/
30 {
31 	struct passwd *pp;
32 	uid_t	euid;
33 
34 	/* Set locale environment variables local definitions */
35 	(void) setlocale(LC_ALL, "");
36 #if	!defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
37 #define	TEXT_DOMAIN "SYS_TEST"  /* Use this only if it wasn't */
38 #endif
39 	(void) textdomain(TEXT_DOMAIN);
40 
41 	euid = geteuid();
42 	pp = getpwuid(euid);
43 	if (pp == 0) {
44 		(void) printf(gettext(MSG), euid);
45 		exit(1);
46 	}
47 	(void) printf("%s\n", pp->pw_name);
48 	return (0);
49 }
50