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