Commit 1abf13db authored by Bruce Momjian's avatar Bruce Momjian

Add get_home_path() to use USERPROFILE on Win32 and HOME on Unix.

parent 19cd31b0
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 2000-2003, PostgreSQL Global Development Group * Copyright (c) 2000-2003, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.87 2004/05/23 22:20:10 neilc Exp $ * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.88 2004/08/18 02:59:11 momjian Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include "common.h" #include "common.h"
...@@ -1078,13 +1078,13 @@ expand_tilde(char **filename) ...@@ -1078,13 +1078,13 @@ expand_tilde(char **filename)
if (**filename == '~') if (**filename == '~')
{ {
char *fn; char *fn;
char *home;
char oldp, char oldp,
*p; *p;
struct passwd *pw; struct passwd *pw;
char home[MAXPGPATH];
fn = *filename; fn = *filename;
home = NULL; *home = '\0';
p = fn + 1; p = fn + 1;
while (*p != '/' && *p != '\0') while (*p != '/' && *p != '\0')
...@@ -1094,12 +1094,12 @@ expand_tilde(char **filename) ...@@ -1094,12 +1094,12 @@ expand_tilde(char **filename)
*p = '\0'; *p = '\0';
if (*(fn + 1) == '\0') if (*(fn + 1) == '\0')
home = getenv("HOME"); get_home_path(home);
else if ((pw = getpwnam(fn + 1)) != NULL) else if ((pw = getpwnam(fn + 1)) != NULL)
home = pw->pw_dir; StrNCpy(home, pw->pw_dir, MAXPGPATH);
*p = oldp; *p = oldp;
if (home) if (strlen(home) != 0)
{ {
char *newfn; char *newfn;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 2000-2003, PostgreSQL Global Development Group * Copyright (c) 2000-2003, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.34 2004/01/25 03:07:22 neilc Exp $ * $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.35 2004/08/18 02:59:11 momjian Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include "input.h" #include "input.h"
...@@ -171,7 +171,7 @@ initializeInput(int flags) ...@@ -171,7 +171,7 @@ initializeInput(int flags)
#ifdef USE_READLINE #ifdef USE_READLINE
if (flags & 1) if (flags & 1)
{ {
const char *home; char home[MAXPGPATH];
useReadline = true; useReadline = true;
initialize_readline(); initialize_readline();
...@@ -180,8 +180,7 @@ initializeInput(int flags) ...@@ -180,8 +180,7 @@ initializeInput(int flags)
if (GetVariable(pset.vars, "HISTSIZE") == NULL) if (GetVariable(pset.vars, "HISTSIZE") == NULL)
SetVariable(pset.vars, "HISTSIZE", "500"); SetVariable(pset.vars, "HISTSIZE", "500");
using_history(); using_history();
home = getenv("HOME"); if (get_home_path(home))
if (home)
{ {
char *psql_history; char *psql_history;
...@@ -231,10 +230,9 @@ finishInput(int exitstatus, void *arg) ...@@ -231,10 +230,9 @@ finishInput(int exitstatus, void *arg)
#ifdef USE_READLINE #ifdef USE_READLINE
if (useHistory) if (useHistory)
{ {
char *home; char home[MAXPGPATH];
home = getenv("HOME"); if (get_home_path(home))
if (home)
{ {
char *psql_history; char *psql_history;
int hist_size; int hist_size;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 2000-2003, PostgreSQL Global Development Group * Copyright (c) 2000-2003, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.95 2004/06/03 00:07:37 momjian Exp $ * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.96 2004/08/18 02:59:11 momjian Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
...@@ -570,8 +570,8 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options) ...@@ -570,8 +570,8 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
static void static void
process_psqlrc(char *argv0) process_psqlrc(char *argv0)
{ {
char *home;
char *psqlrc; char *psqlrc;
char home[MAXPGPATH];
char global_file[MAXPGPATH]; char global_file[MAXPGPATH];
char my_exec_path[MAXPGPATH]; char my_exec_path[MAXPGPATH];
char etc_path[MAXPGPATH]; char etc_path[MAXPGPATH];
...@@ -582,7 +582,7 @@ process_psqlrc(char *argv0) ...@@ -582,7 +582,7 @@ process_psqlrc(char *argv0)
snprintf(global_file, MAXPGPATH, "%s/%s", etc_path, SYSPSQLRC); snprintf(global_file, MAXPGPATH, "%s/%s", etc_path, SYSPSQLRC);
process_psqlrc_file(global_file); process_psqlrc_file(global_file);
if ((home = getenv("HOME")) != NULL) if (get_home_path(home))
{ {
psqlrc = pg_malloc(strlen(home) + 1 + strlen(PSQLRC) + 1); psqlrc = pg_malloc(strlen(home) + 1 + strlen(PSQLRC) + 1);
sprintf(psqlrc, "%s/%s", home, PSQLRC); sprintf(psqlrc, "%s/%s", home, PSQLRC);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/port.h,v 1.53 2004/08/17 14:38:38 momjian Exp $ * $PostgreSQL: pgsql/src/include/port.h,v 1.54 2004/08/18 02:59:11 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -50,6 +50,7 @@ extern void get_lib_path(const char *my_exec_path, char *ret_path); ...@@ -50,6 +50,7 @@ extern void get_lib_path(const char *my_exec_path, char *ret_path);
extern void get_pkglib_path(const char *my_exec_path, char *ret_path); extern void get_pkglib_path(const char *my_exec_path, char *ret_path);
extern void get_locale_path(const char *my_exec_path, char *ret_path); extern void get_locale_path(const char *my_exec_path, char *ret_path);
extern void set_pglocale_pgservice(const char *argv0, const char *app); extern void set_pglocale_pgservice(const char *argv0, const char *app);
extern bool get_home_path(char *ret_path);
/* /*
* is_absolute_path * is_absolute_path
...@@ -74,9 +75,6 @@ extern void set_pglocale_pgservice(const char *argv0, const char *app); ...@@ -74,9 +75,6 @@ extern void set_pglocale_pgservice(const char *argv0, const char *app);
#endif #endif
/* Portable way to find binaries */ /* Portable way to find binaries */
extern int find_my_exec(const char *argv0, char *retpath); extern int find_my_exec(const char *argv0, char *retpath);
extern int find_other_exec(const char *argv0, const char *target, extern int find_other_exec(const char *argv0, const char *target,
...@@ -104,6 +102,12 @@ extern int find_other_exec(const char *argv0, const char *target, ...@@ -104,6 +102,12 @@ extern int find_other_exec(const char *argv0, const char *target,
#define SYSTEMQUOTE "" #define SYSTEMQUOTE ""
#endif #endif
#ifdef WIN32
#define HOMEDIR "USERPROFILE"
#else
#define HOMEDIR "HOME"
#endif
/* Portable delay handling */ /* Portable delay handling */
extern void pg_usleep(long microsec); extern void pg_usleep(long microsec);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.280 2004/08/17 04:24:23 tgl Exp $ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.281 2004/08/18 02:59:11 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -3093,7 +3093,7 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username) ...@@ -3093,7 +3093,7 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
{ {
FILE *fp; FILE *fp;
char *pgpassfile; char *pgpassfile;
char *home; char home[MAXPGPATH];
struct stat stat_buf; struct stat stat_buf;
#define LINELEN NAMEDATALEN*5 #define LINELEN NAMEDATALEN*5
...@@ -3112,8 +3112,7 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username) ...@@ -3112,8 +3112,7 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
port = DEF_PGPORT_STR; port = DEF_PGPORT_STR;
/* Look for it in the home dir */ /* Look for it in the home dir */
home = getenv("HOME"); if (!get_home_path(home))
if (!home)
return NULL; return NULL;
pgpassfile = malloc(strlen(home) + 1 + strlen(PGPASSFILE) + 1); pgpassfile = malloc(strlen(home) + 1 + strlen(PGPASSFILE) + 1);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/port/path.c,v 1.30 2004/08/13 14:47:23 tgl Exp $ * $PostgreSQL: pgsql/src/port/path.c,v 1.31 2004/08/18 02:59:12 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -370,6 +370,27 @@ set_pglocale_pgservice(const char *argv0, const char *app) ...@@ -370,6 +370,27 @@ set_pglocale_pgservice(const char *argv0, const char *app)
} }
/*
* get_include_path
*/
bool
get_home_path(char *ret_path)
{
if (getenv(HOMEDIR) == NULL)
{
*ret_path = '\0';
return false;
}
else
{
StrNCpy(ret_path, getenv(HOMEDIR), MAXPGPATH);
canonicalize_path(ret_path);
return true;
}
}
/* /*
* make_relative - adjust path to be relative to bin/ * make_relative - adjust path to be relative to bin/
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment