Libbarrett  1.2.4
include/barrett/config.h
00001 #ifndef __LIBBARRETT_CONFIG_H
00002 #define __LIBBARRETT_CONFIG_H
00003 
00004 #include <string>
00005 #include <unistd.h>
00006 #include <sys/types.h>
00007 #include <sys/stat.h>
00008 #include <pwd.h>
00009 
00010 namespace barrett {
00011   static const std::string EtcPathRelative(const std::string &relpath) {
00012 
00013 std::string path = "/.barrett/";
00014 char *home;
00015 struct stat statbuf;
00016  
00017   home = getenv("HOME");
00018   if(home == NULL)
00019         home = getpwuid(getuid())->pw_dir;
00020   path = home + path;
00021   if(stat(path.c_str(), &statbuf) != -1){
00022         if(S_ISDIR(statbuf.st_mode)) {
00023                 return (path + relpath);
00024         }
00025   }     
00026     return std::string("/etc/barrett/") + relpath;
00027   }
00028 }
00029 
00030 #endif //ifndef __LIBBARRETT_CONFIG_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines