/ Published in: C++
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.
- 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;
You need to login to post a comment.