1 #include "usernamefrompwuid.h"
2 #ifdef I_PWD
3 #  include <sys/types.h>
4 #  include <pwd.h>
5 #endif
6 
7 /* This piece of code uses getpwuid from pwd.h to determine the current
8  * user name.
9  * Since pwd.h might not be available and perl's configure script probed
10  * for this, we require access to perl's config.h. Whether or not we have that
11  * can be determined by the Makefile.PL in myldr/. It writes the
12  * usernamefrompwuid.h file for us. In the header, we include config.h if
13  * available or sets I_PWD to undefined.
14  * -- Steffen Mueller
15  */
16 
get_username_from_getpwuid()17 char *get_username_from_getpwuid () {
18     char *username = NULL;
19 #ifdef I_PWD
20     struct passwd *userdata = NULL;
21     userdata = getpwuid(getuid());
22     if (userdata)
23         username = userdata->pw_name;
24 #endif
25     return(username);
26 }
27