home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume20 / reactivekbd / part01 / myabspath.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-16  |  869 b   |  55 lines

  1. /* Mark James 89/5/24*/
  2.  
  3.  
  4. #include "myabspath.h"
  5. #include <pwd.h>
  6. #include <stdio.h>
  7. #include <ctype.h>
  8. #include <strings.h>
  9.  
  10.  
  11. /* returns 0 on success, NO_HOME if getenv("HOME") fails, NO_USER if ~user does not exist */
  12.  
  13. myabspath(path,buff)
  14. char *path;
  15. char *buff;
  16. {
  17.     char *homedir;
  18.     char *getenv();
  19.     char username[MAX_USER_NAME];
  20.     int i;
  21.     struct passwd *pwd;
  22.  
  23.     while (isspace(path[0])&&path[0])
  24.         path++;
  25.     if(path[0]=='~'){
  26.         path++;
  27.         if((path[0]=='/') || (path[0]==0)){
  28.             if((homedir=getenv("HOME"))==0)
  29.                 return(NO_HOME);
  30.             strcpy(buff,homedir);
  31.             strcat(buff,path);
  32.             return(0);
  33.         }
  34.         else
  35.         {
  36.             for(i=0;(path[0]!='/')&&(path[0]!=0);i++,path++)
  37.                 username[i]=path[0];
  38.             username[i]=0;
  39.             if((pwd=getpwnam(username))==0)
  40.                 return(NO_USER);
  41.             strcpy(buff,pwd->pw_dir);
  42.             strcat(buff,path);        
  43.         }
  44.     }
  45.     else
  46.     {
  47.         strcpy(buff,path);
  48.         return(0);
  49.     }
  50. }
  51.  
  52.  
  53.  
  54.  
  55.