/* LibRCC - module detecting user's home directory Copyright (C) 2005-2008 Suren A. Chilingaryan This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include #include #include #include "../config.h" #ifdef HAVE_UNISTD_H # include #endif /* HAVE_UNISTD_H */ #ifdef HAVE_SYS_TYPES_H # include #endif /* HAVE_SYS_TYPES_H */ #ifdef HAVE_SYS_STAT_H # include #endif /* HAVE_SYS_STAT_H */ #ifdef HAVE_PWD_H # include #endif /* HAVE_PWD_H */ #include "rcchome.h" char *rcc_home_dir = NULL; void rccHomeSet() { char *tmp; #ifdef HAVE_PWD_H struct passwd *pw; #endif /* HAVE_PWD_H */ tmp = getenv ("HOME"); if (tmp) rcc_home_dir = strdup (tmp); #ifdef HAVE_PWD_H else { setpwent (); pw = getpwuid(getuid ()); endpwent (); if ((pw)&&(pw->pw_dir)) rcc_home_dir = strdup (pw->pw_dir); } #endif /* HAVE_PWD_H */ if (!rcc_home_dir) rcc_home_dir = strdup("/"); } void rccHomeFree() { if (rcc_home_dir) { free(rcc_home_dir); rcc_home_dir = NULL; } }