1 /*	$NetBSD: username.c,v 1.1.1.1 2009/06/23 10:09:01 tron Exp $	*/
2 
3 /*++
4 /* NAME
5 /*	username 3
6 /* SUMMARY
7 /*	lookup name of real user
8 /* SYNOPSIS
9 /*	#include <username.h>
10 /*
11 /*	const char *username()
12 /* DESCRIPTION
13 /*	username() jumps whatever system-specific hoops it takes to
14 /*	get the name of the user who started the process. The result
15 /*	is volatile. Make a copy if it is to be used for an appreciable
16 /*	amount of time.
17 /* LICENSE
18 /* .ad
19 /* .fi
20 /*	The Secure Mailer license must be distributed with this software.
21 /* AUTHOR(S)
22 /*	Wietse Venema
23 /*	IBM T.J. Watson Research
24 /*	P.O. Box 704
25 /*	Yorktown Heights, NY 10598, USA
26 /*--*/
27 
28 /* System library. */
29 
30 #include <sys_defs.h>
31 #include <unistd.h>
32 #include <pwd.h>
33 
34 /* Utility library. */
35 
36 #include "username.h"
37 
38 /* username - get name of user */
39 
40 const char *username(void)
41 {
42     uid_t   uid;
43     struct passwd *pwd;
44 
45     uid = getuid();
46     if ((pwd = getpwuid(uid)) == 0)
47 	return (0);
48     return (pwd->pw_name);
49 }
50