1: /* $Header$ */ 2: 3: /* 4: * Author: Peter J. Nicklin 5: */ 6: 7: /* 8: * gethdir() returns a pointer to a string containing the pathname of the 9: * root project directory belonging to username. If username is null or a 10: * zero length string, the root project directory belonging to the current 11: * user returned. A null pointer is returned on error. 12: */ 13: #include <stdio.h> 14: #include <pwd.h> 15: #include "null.h" 16: #include "path.h" 17: 18: char * 19: gethdir(username) 20: char *username; /* user's login name */ 21: { 22: char *getenv(); /* get environment variable */ 23: char *hdir; /* pointer to home directory pathname */ 24: char *strcpy(); /* string copy */ 25: struct passwd *getpwnam(); /* get password file entry by name */ 26: struct passwd *getpwuid(); /* get password file entry by uid */ 27: struct passwd *pw; /* passwd struct pointer */ 28: 29: if (username == NULL || *username == '\0') 30: { 31: if ((hdir = getenv("ROOTPROJECT")) != NULL) 32: return(hdir); 33: if ((hdir = getenv("HOME")) != NULL) 34: return(hdir); 35: pw = getpwuid(getuid()); 36: } 37: else if ((pw = getpwnam(username)) == NULL) 38: { 39: warn("unknown user %s", username); 40: return(NULL); 41: } 42: return(pw->pw_dir); 43: }