File: usernamefrompwuid.c

package info (click to toggle)
libpar-packer-perl 0.978-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 1,324 kB
  • ctags: 494
  • sloc: perl: 19,945; ansic: 904; makefile: 64
file content (31 lines) | stat: -rw-r--r-- 846 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "usernamefrompwuid.h"
#ifdef I_PWD
#  include <sys/types.h>
#  include <pwd.h>
#endif

/* This piece of code uses getpwuid from pwd.h to determine the current
 * use name.
 * Since pwd.h might not be available and perl's configure script probed
 * for this, we require access to perl's config.h. Whether or not we have that
 * can be determined by the Makefile.PL in myldr/. It writes the
 * usernamefrompwuid.h file for us. In the header, we include config.h if
 * available or sets I_PWD to undefined.
 * -- Steffen Mueller
 */

char *get_username_from_getpwuid () {
#ifdef I_PWD
    char *username = NULL;
    struct passwd *userdata = NULL;
    uid_t uid;
    uid = getuid();
    if (uid) {
        userdata = getpwuid(uid);
        username = userdata->pw_name;
    }
#else
    char *username = NULL;
#endif
    return(username);
}