1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-02 09:02:37 +03:00

Make the various places that determine the user's "home directory"

consistent.  On Unix we now always consult getpwuid(); $HOME isn't used
at all.  On Windows the code currently consults $USERPROFILE, or $HOME
if that's not defined, but I expect this will change as soon as the win32
hackers come to a consensus.  Nothing done yet about changing the file
names used underneath $USERPROFILE.
This commit is contained in:
Tom Lane
2005-01-06 01:00:12 +00:00
parent fdbeaaf90a
commit d97ae8230e
5 changed files with 72 additions and 76 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/port/path.c,v 1.46 2004/12/31 22:03:53 pgsql Exp $
* $PostgreSQL: pgsql/src/port/path.c,v 1.47 2005/01/06 01:00:12 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -16,6 +16,10 @@
#include "c.h"
#include <ctype.h>
#include <sys/stat.h>
#ifndef WIN32
#include <unistd.h>
#endif
#include "pg_config_paths.h"
@ -445,19 +449,29 @@ get_locale_path(const char *my_exec_path, char *ret_path)
bool
get_home_path(char *ret_path)
{
const char *homedir = getenv(HOMEDIR);
#ifndef WIN32
char pwdbuf[BUFSIZ];
struct passwd pwdstr;
struct passwd *pwd = NULL;
if (homedir == NULL)
{
*ret_path = '\0';
if (pqGetpwuid(geteuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pwd) != 0)
return false;
}
else
{
StrNCpy(ret_path, homedir, MAXPGPATH);
canonicalize_path(ret_path);
return true;
}
StrNCpy(ret_path, pwd->pw_dir, MAXPGPATH);
return true;
#else
/* TEMPORARY PLACEHOLDER IMPLEMENTATION */
const char *homedir;
homedir = getenv("USERPROFILE");
if (homedir == NULL)
homedir = getenv("HOME");
if (homedir == NULL)
return false;
StrNCpy(ret_path, homedir, MAXPGPATH);
return true;
#endif
}