Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1abf13d

Browse files
committed
Add get_home_path() to use USERPROFILE on Win32 and HOME on Unix.
1 parent19cd31b commit1abf13d

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
charoldp,
10831082
*p;
10841083
structpasswd*pw;
1084+
charhome[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
elseif ((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
#ifdefUSE_READLINE
172172
if (flags&1)
173173
{
174-
constchar*home;
174+
charhome[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
#ifdefUSE_READLINE
232231
if (useHistory)
233232
{
234-
char*home;
233+
charhome[MAXPGPATH];
235234

236-
home=getenv("HOME");
237-
if (home)
235+
if (get_home_path(home))
238236
{
239237
char*psql_history;
240238
inthist_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
staticvoid
571571
process_psqlrc(char*argv0)
572572
{
573-
char*home;
574573
char*psqlrc;
574+
charhome[MAXPGPATH];
575575
charglobal_file[MAXPGPATH];
576576
charmy_exec_path[MAXPGPATH];
577577
charetc_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
externvoidget_pkglib_path(constchar*my_exec_path,char*ret_path);
5151
externvoidget_locale_path(constchar*my_exec_path,char*ret_path);
5252
externvoidset_pglocale_pgservice(constchar*argv0,constchar*app);
53+
externboolget_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
externintfind_my_exec(constchar*argv0,char*retpath);
8280
externintfind_other_exec(constchar*argv0,constchar*target,
@@ -104,6 +102,12 @@ extern int find_other_exec(const char *argv0, const char *target,
104102
#defineSYSTEMQUOTE ""
105103
#endif
106104

105+
#ifdefWIN32
106+
#defineHOMEDIR"USERPROFILE"
107+
#else
108+
#defineHOMEDIR"HOME"
109+
#endif
110+
107111
/* Portable delay handling */
108112
externvoidpg_usleep(longmicrosec);
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+
charhome[MAXPGPATH];
30973097
structstatstat_buf;
30983098

30993099
#defineLINELEN 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
returnNULL;
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)

[8]ページ先頭

©2009-2025 Movatter.jp