Back to index

radiance  4R0+20100331
Functions | Variables
gethomedir.c File Reference
#include "copyright.h"
#include <stdlib.h>
#include <string.h>
#include "rtio.h"
#include <unistd.h>
#include <pwd.h>
#include <sys/types.h>

Go to the source code of this file.

Functions

char * gethomedir (char *uname, char *path, int plen)

Variables

static const char RCSid [] = "$Id: gethomedir.c,v 1.1 2003/10/27 10:20:58 schorsch Exp $"

Function Documentation

char* gethomedir ( char *  uname,
char *  path,
int  plen 
)

Definition at line 52 of file gethomedir.c.

{
       struct passwd *pwent;
       uid_t uid;
       char *cp;

       if (uname == NULL || *uname == '\0') {    /* ours */
              if ((cp = getenv("HOME")) != NULL) {
                     strncpy(path, cp, plen);
                     path[plen-1] = '\0';
                     return path;
              }
              uid = getuid();
              if ((pwent = getpwuid(uid)) == NULL)
                     return(NULL); /* we don't exist ?!? */
              strncpy(path, pwent->pw_dir, plen);
              path[plen-1] = '\0';
              return path;
       }
       /* someone else */
       if ((pwent = getpwnam(uname)) == NULL)
              return(NULL); /* no such user */

       strncpy(path, pwent->pw_dir, plen);
       path[plen-1] = '\0';
       return path;
}

Here is the caller graph for this function:


Variable Documentation

const char RCSid[] = "$Id: gethomedir.c,v 1.1 2003/10/27 10:20:58 schorsch Exp $" [static]

Definition at line 2 of file gethomedir.c.