whoami.c revision 35:6307fd20d0f7
1/*
2 * Copyright 1988 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
18#include <unistd.h>
19#include <sys/types.h>
20#include <pwd.h>
21#include <locale.h>
22#include <stdlib.h>
23
24#define	MSG	"whoami: no login associated with uid %u.\n"
25
26/*
27 * whoami
28 */
29
30int
31main(int argc, char *argv[])
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	printf("%s\n", pp->pw_name);
50	return (0);
51}
52