Sync usage with man page.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / util / username.c
blobaeee03d6ed6c147ddf8e7761d87f36df2de0bdb3
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* username 3
6 /* SUMMARY
7 /* lookup name of real user
8 /* SYNOPSIS
9 /* #include <username.h>
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 /*--*/
28 /* System library. */
30 #include <sys_defs.h>
31 #include <unistd.h>
32 #include <pwd.h>
34 /* Utility library. */
36 #include "username.h"
38 /* username - get name of user */
40 const char *username(void)
42 uid_t uid;
43 struct passwd *pwd;
45 uid = getuid();
46 if ((pwd = getpwuid(uid)) == 0)
47 return (0);
48 return (pwd->pw_name);