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

Commit54691d4

Browse files
committed
Fix psql \e and \! for Win32.
1 parente48b9b5 commit54691d4

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

‎src/bin/pg_ctl/pg_ctl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.44 2004/10/27 19:44:14 momjian Exp $
7+
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.45 2004/11/04 22:25:12 momjian Exp $
88
*
99
*-------------------------------------------------------------------------
1010
*/
@@ -335,15 +335,15 @@ start_postmaster(void)
335335
* http://dev.remotenetworktechnology.com/cmd/cmdfaq.htm
336336
*/
337337
if (log_file!=NULL)
338-
#if !defined(WIN32)/* Cygwin doesn't have START */
338+
#ifndefWIN32/* Cygwin doesn't have START */
339339
snprintf(cmd,MAXPGPATH,"%s\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1 &%s",
340340
#else
341341
snprintf(cmd,MAXPGPATH,"%sSTART /B \"\" \"%s\" %s%s < \"%s\" >> \"%s\" 2>&1%s",
342342
#endif
343343
SYSTEMQUOTE,postgres_path,pgdata_opt,post_opts,
344344
DEVNULL,log_file,SYSTEMQUOTE);
345345
else
346-
#if !defined(WIN32)/* Cygwin doesn't have START */
346+
#ifndefWIN32/* Cygwin doesn't have START */
347347
snprintf(cmd,MAXPGPATH,"%s\"%s\" %s%s < \"%s\" 2>&1 &%s",
348348
#else
349349
snprintf(cmd,MAXPGPATH,"%sSTART /B \"\" \"%s\" %s%s < \"%s\" 2>&1%s",

‎src/bin/psql/command.c

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2004, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.129 2004/10/16 03:10:16 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.130 2004/11/04 22:25:14 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"command.h"
@@ -23,6 +23,10 @@
2323
#include<io.h>
2424
#include<fcntl.h>
2525
#include<direct.h>
26+
#ifndefWIN32_CLIENT_ONLY
27+
#include<sys/types.h>/* for umask() */
28+
#include<sys/stat.h>/* for stat() */
29+
#endif
2630
#endif
2731

2832
#include"libpq-fe.h"
@@ -1097,7 +1101,7 @@ editFile(const char *fname)
10971101
#ifndefWIN32
10981102
"exec "
10991103
#endif
1100-
"%s '%s'",editorName,fname);
1104+
"%s\"%s\" \"%s\"%s",SYSTEMQUOTE,editorName,fname,SYSTEMQUOTE);
11011105
result=system(sys);
11021106
if (result==-1)
11031107
psql_error("could not start editor \"%s\"\n",editorName);
@@ -1119,7 +1123,7 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf)
11191123
boolerror= false;
11201124
intfd;
11211125

1122-
#ifndefWIN32
1126+
#ifndefWIN32_CLIENT_ONLY
11231127
structstatbefore,
11241128
after;
11251129
#endif
@@ -1130,13 +1134,35 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf)
11301134
{
11311135
/* make a temp file to edit */
11321136
#ifndefWIN32
1133-
constchar*tmpdirenv=getenv("TMPDIR");
1137+
constchar*tmpdir=getenv("TMPDIR");
11341138

1135-
snprintf(fnametmp,sizeof(fnametmp),"%s/psql.edit.%d.%d",
1136-
tmpdirenv ?tmpdirenv :"/tmp",geteuid(), (int)getpid());
1139+
if (!tmpdir)
1140+
tmpdir="/tmp";
1141+
#else
1142+
chartmpdir[MAXPGPATH];
1143+
intret;
1144+
1145+
ret=GetTempPath(MAXPGPATH,tmpdir);
1146+
if (ret==0||ret>MAXPGPATH)
1147+
{
1148+
psql_error("Can not locate temporary directory: %s",
1149+
!ret ?strerror(errno) :"");
1150+
return false;
1151+
}
1152+
/*
1153+
*No canonicalize_path() here.
1154+
*EDIT.EXE run from CMD.EXE prepends the current directory to the
1155+
*supplied path unless we use only backslashes, so we do that.
1156+
*/
1157+
#endif
1158+
snprintf(fnametmp,sizeof(fnametmp),"%s%spsql.edit.%d",tmpdir,
1159+
#ifndefWIN32
1160+
"/",
11371161
#else
1138-
GetTempFileName(".","psql",0,fnametmp);
1162+
"",/* trailing separator already present */
11391163
#endif
1164+
(int)getpid());
1165+
11401166
fname= (constchar*)fnametmp;
11411167

11421168
fd=open(fname,O_WRONLY |O_CREAT |O_EXCL,0600);
@@ -1174,7 +1200,7 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf)
11741200
}
11751201
}
11761202

1177-
#ifndefWIN32
1203+
#ifndefWIN32_CLIENT_ONLY
11781204
if (!error&&stat(fname,&before)!=0)
11791205
{
11801206
psql_error("%s: %s\n",fname,strerror(errno));
@@ -1186,7 +1212,7 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf)
11861212
if (!error)
11871213
error= !editFile(fname);
11881214

1189-
#ifndefWIN32
1215+
#ifndefWIN32_CLIENT_ONLY
11901216
if (!error&&stat(fname,&after)!=0)
11911217
{
11921218
psql_error("%s: %s\n",fname,strerror(errno));
@@ -1509,9 +1535,13 @@ do_shell(const char *command)
15091535
if (!command)
15101536
{
15111537
char*sys;
1512-
constchar*shellName;
1538+
constchar*shellName=NULL;
15131539

1514-
shellName=getenv("SHELL");
1540+
#ifdefWIN32
1541+
shellName=getenv("COMSPEC");
1542+
#endif
1543+
if (shellName==NULL)
1544+
shellName=getenv("SHELL");
15151545
if (shellName==NULL)
15161546
shellName=DEFAULT_SHELL;
15171547

@@ -1520,7 +1550,7 @@ do_shell(const char *command)
15201550
#ifndefWIN32
15211551
"exec "
15221552
#endif
1523-
"%s",shellName);
1553+
"%s\"%s\"%s",SYSTEMQUOTE,shellName,SYSTEMQUOTE);
15241554
result=system(sys);
15251555
free(sys);
15261556
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp