xref: /illumos-gate/usr/src/ucbcmd/whoami/whoami.c (revision 8c0b080c)
178b6ed60Scraigm /*
2*f22acdffSgbrunett  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
378b6ed60Scraigm  * Use is subject to license terms.
478b6ed60Scraigm  */
578b6ed60Scraigm 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
77c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved.  The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
157c478bd9Sstevel@tonic-gate #include <unistd.h>
167c478bd9Sstevel@tonic-gate #include <sys/types.h>
177c478bd9Sstevel@tonic-gate #include <pwd.h>
187c478bd9Sstevel@tonic-gate #include <locale.h>
197c478bd9Sstevel@tonic-gate #include <stdlib.h>
207c478bd9Sstevel@tonic-gate 
217c478bd9Sstevel@tonic-gate #define	MSG	"whoami: no login associated with uid %u.\n"
227c478bd9Sstevel@tonic-gate 
237c478bd9Sstevel@tonic-gate /*
247c478bd9Sstevel@tonic-gate  * whoami
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
2778b6ed60Scraigm int
main(int argc,char * argv[])2878b6ed60Scraigm main(int argc, char *argv[])
29*f22acdffSgbrunett /*ARGSUSED*/
307c478bd9Sstevel@tonic-gate {
3178b6ed60Scraigm 	struct passwd *pp;
327c478bd9Sstevel@tonic-gate 	uid_t	euid;
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate 	/* Set locale environment variables local definitions */
357c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
367c478bd9Sstevel@tonic-gate #if	!defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
377c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"  /* Use this only if it wasn't */
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate 	euid = geteuid();
427c478bd9Sstevel@tonic-gate 	pp = getpwuid(euid);
437c478bd9Sstevel@tonic-gate 	if (pp == 0) {
447c478bd9Sstevel@tonic-gate 		(void) printf(gettext(MSG), euid);
457c478bd9Sstevel@tonic-gate 		exit(1);
467c478bd9Sstevel@tonic-gate 	}
47*f22acdffSgbrunett 	(void) printf("%s\n", pp->pw_name);
4878b6ed60Scraigm 	return (0);
497c478bd9Sstevel@tonic-gate }
50