Skip to content

Commit 1abf13d

Browse files
committed
Add get_home_path() to use USERPROFILE on Win32 and HOME on Unix.
1 parent 19cd31b commit 1abf13d

File tree

6 files changed

+47
-25
lines changed

6 files changed

+47
-25
lines changed

src/bin/psql/common.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.87 2004/05/23 22:20:10 neilc Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.88 2004/08/18 02:59:11 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "common.h"
@@ -1078,13 +1078,13 @@ expand_tilde(char **filename)
10781078
if (**filename == '~')
10791079
{
10801080
char *fn;
1081-
char *home;
10821081
char oldp,
10831082
*p;
10841083
struct passwd *pw;
1084+
char home[MAXPGPATH];
10851085

10861086
fn = *filename;
1087-
home = NULL;
1087+
*home = '\0';
10881088

10891089
p = fn + 1;
10901090
while (*p != '/' && *p != '\0')
@@ -1094,12 +1094,12 @@ expand_tilde(char **filename)
10941094
*p = '\0';
10951095

10961096
if (*(fn + 1) == '\0')
1097-
home = getenv("HOME");
1097+
get_home_path(home);
10981098
else if ((pw = getpwnam(fn + 1)) != NULL)
1099-
home = pw->pw_dir;
1099+
StrNCpy(home, pw->pw_dir, MAXPGPATH);
11001100

11011101
*p = oldp;
1102-
if (home)
1102+
if (strlen(home) != 0)
11031103
{
11041104
char *newfn;
11051105

src/bin/psql/input.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.34 2004/01/25 03:07:22 neilc Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.35 2004/08/18 02:59:11 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "input.h"
@@ -171,7 +171,7 @@ initializeInput(int flags)
171171
#ifdef USE_READLINE
172172
if (flags & 1)
173173
{
174-
const char *home;
174+
char home[MAXPGPATH];
175175

176176
useReadline = true;
177177
initialize_readline();
@@ -180,8 +180,7 @@ initializeInput(int flags)
180180
if (GetVariable(pset.vars, "HISTSIZE") == NULL)
181181
SetVariable(pset.vars, "HISTSIZE", "500");
182182
using_history();
183-
home = getenv("HOME");
184-
if (home)
183+
if (get_home_path(home))
185184
{
186185
char *psql_history;
187186

@@ -231,10 +230,9 @@ finishInput(int exitstatus, void *arg)
231230
#ifdef USE_READLINE
232231
if (useHistory)
233232
{
234-
char *home;
233+
char home[MAXPGPATH];
235234

236-
home = getenv("HOME");
237-
if (home)
235+
if (get_home_path(home))
238236
{
239237
char *psql_history;
240238
int hist_size;

src/bin/psql/startup.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.95 2004/06/03 00:07:37 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.96 2004/08/18 02:59:11 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99

@@ -570,8 +570,8 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
570570
static void
571571
process_psqlrc(char *argv0)
572572
{
573-
char *home;
574573
char *psqlrc;
574+
char home[MAXPGPATH];
575575
char global_file[MAXPGPATH];
576576
char my_exec_path[MAXPGPATH];
577577
char etc_path[MAXPGPATH];
@@ -582,7 +582,7 @@ process_psqlrc(char *argv0)
582582
snprintf(global_file, MAXPGPATH, "%s/%s", etc_path, SYSPSQLRC);
583583
process_psqlrc_file(global_file);
584584

585-
if ((home = getenv("HOME")) != NULL)
585+
if (get_home_path(home))
586586
{
587587
psqlrc = pg_malloc(strlen(home) + 1 + strlen(PSQLRC) + 1);
588588
sprintf(psqlrc, "%s/%s", home, PSQLRC);

src/include/port.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/port.h,v 1.53 2004/08/17 14:38:38 momjian Exp $
9+
* $PostgreSQL: pgsql/src/include/port.h,v 1.54 2004/08/18 02:59:11 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -50,6 +50,7 @@ extern void get_lib_path(const char *my_exec_path, char *ret_path);
5050
extern void get_pkglib_path(const char *my_exec_path, char *ret_path);
5151
extern void get_locale_path(const char *my_exec_path, char *ret_path);
5252
extern void set_pglocale_pgservice(const char *argv0, const char *app);
53+
extern bool get_home_path(char *ret_path);
5354

5455
/*
5556
* is_absolute_path
@@ -74,9 +75,6 @@ extern void set_pglocale_pgservice(const char *argv0, const char *app);
7475
#endif
7576

7677

77-
78-
79-
8078
/* Portable way to find binaries */
8179
extern int find_my_exec(const char *argv0, char *retpath);
8280
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,
104102
#define SYSTEMQUOTE ""
105103
#endif
106104

105+
#ifdef WIN32
106+
#define HOMEDIR "USERPROFILE"
107+
#else
108+
#define HOMEDIR "HOME"
109+
#endif
110+
107111
/* Portable delay handling */
108112
extern void pg_usleep(long microsec);
109113

src/interfaces/libpq/fe-connect.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.280 2004/08/17 04:24:23 tgl Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.281 2004/08/18 02:59:11 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3093,7 +3093,7 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
30933093
{
30943094
FILE *fp;
30953095
char *pgpassfile;
3096-
char *home;
3096+
char home[MAXPGPATH];
30973097
struct stat stat_buf;
30983098

30993099
#define LINELEN NAMEDATALEN*5
@@ -3112,8 +3112,7 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
31123112
port = DEF_PGPORT_STR;
31133113

31143114
/* Look for it in the home dir */
3115-
home = getenv("HOME");
3116-
if (!home)
3115+
if (!get_home_path(home))
31173116
return NULL;
31183117

31193118
pgpassfile = malloc(strlen(home) + 1 + strlen(PGPASSFILE) + 1);

src/port/path.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/port/path.c,v 1.30 2004/08/13 14:47:23 tgl Exp $
11+
* $PostgreSQL: pgsql/src/port/path.c,v 1.31 2004/08/18 02:59:12 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -370,6 +370,27 @@ set_pglocale_pgservice(const char *argv0, const char *app)
370370
}
371371

372372

373+
/*
374+
* get_include_path
375+
*/
376+
bool
377+
get_home_path(char *ret_path)
378+
{
379+
if (getenv(HOMEDIR) == NULL)
380+
{
381+
*ret_path = '\0';
382+
return false;
383+
}
384+
else
385+
{
386+
StrNCpy(ret_path, getenv(HOMEDIR), MAXPGPATH);
387+
canonicalize_path(ret_path);
388+
return true;
389+
}
390+
}
391+
392+
393+
373394
/*
374395
* make_relative - adjust path to be relative to bin/
375396
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy