Back to index

glibc  2.9
getpw.c File Reference
#include <alloca.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <pwd.h>

Go to the source code of this file.


int __getpw (__uid_t uid, char *buf)

Function Documentation

int __getpw ( __uid_t  uid,
char *  buf 

Definition at line 33 of file getpw.c.

  size_t buflen;
  char *tmpbuf;
  struct passwd resbuf, *p;

  if (buf == NULL)
      __set_errno (EINVAL);
      return -1;

  buflen = __sysconf (_SC_GETPW_R_SIZE_MAX);
  tmpbuf = alloca (buflen);

  if (__getpwuid_r (uid, &resbuf, tmpbuf, buflen, &p) != 0)
    return -1;

  if (p == NULL)
    return -1;

  if (sprintf (buf, "%s:%s:%lu:%lu:%s:%s:%s", p->pw_name, p->pw_passwd,
              (unsigned long int) p->pw_uid, (unsigned long int) p->pw_gid,
              p->pw_gecos, p->pw_dir, p->pw_shell) < 0)
    return -1;

  return 0;

Here is the call graph for this function: