Return to Snippet

Revision: 19640
at October 27, 2009 16:39 by xxtjaxx


Initial Code
string get_home(void)
  {
    /* the passwd struct */
    struct passwd *passwd; 
    
    
    /* we pass the current users UID to the struct variable*/
    passwd = getpwuid ( getuid()); 
    
    
    /* 
       then we pass the UID to pw_name which is a char value
       of the /home/ directory
    */
    string user(passwd->pw_name);
    
    
    /*then we make sure we have the full path + our secret config dir*/
    user = "/home/" + user + "/.mkproject/";
    return user;
  }

Initial URL


Initial Description
This one just demonstrates an easy way to get the information via pwuid's. Might not the most elegnt way ut works on every unix I believe.

Initial Title
get the home diectory of the current user unix way

Initial Tags


Initial Language
C++