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

Commit244ee0c

Browse files
committed
Remove pstrdup() call from exec.c because DLLIMPORT flag on
CurrentMemoryContext caused compile problems.Recode to not make a copy of the PATH but copy parts out into MAXPGPATHvariables.
1 parentfcbc95b commit244ee0c

File tree

1 file changed

+25
-34
lines changed

1 file changed

+25
-34
lines changed

‎src/port/exec.c

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/port/exec.c,v 1.14 2004/05/2420:23:50 momjian Exp $
10+
* $PostgreSQL: pgsql/src/port/exec.c,v 1.15 2004/05/2422:35:37 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -28,12 +28,6 @@
2828

2929
#define_(x) gettext(x)
3030

31-
#ifdefFRONTEND
32-
#undef pstrdup
33-
#definepstrdup(p)strdup(p)
34-
#definepfree(p)free(p)
35-
#endif
36-
3731
/* $PATH (or %PATH%) path separator */
3832
#ifdefWIN32
3933
#definePATHSEP ';'
@@ -185,11 +179,8 @@ validate_exec(const char *path)
185179
int
186180
find_my_exec(constchar*argv0,char*retpath)
187181
{
188-
charcwd[MAXPGPATH];
189-
char*p;
190-
char*path,
191-
*startp,
192-
*endp;
182+
charcwd[MAXPGPATH],test_path[MAXPGPATH];
183+
char*path;
193184

194185
if (!getcwd(cwd,MAXPGPATH))
195186
cwd[0]='\0';
@@ -205,9 +196,9 @@ find_my_exec(const char *argv0, char *retpath)
205196
* it).
206197
*/
207198
/* Does argv0 have a separator? */
208-
if ((p=last_path_separator(argv0)))
199+
if ((path=last_path_separator(argv0)))
209200
{
210-
if (*++p=='\0')
201+
if (*++path=='\0')
211202
{
212203
log_error("argv[0] ends with a path separator \"%s\"",argv0);
213204
return-1;
@@ -245,41 +236,41 @@ find_my_exec(const char *argv0, char *retpath)
245236
* Second try: since no explicit path was supplied, the user must have
246237
* been relying on PATH. We'll use the same PATH.
247238
*/
248-
if ((p=getenv("PATH"))&&*p)
239+
if ((path=getenv("PATH"))&&*path)
249240
{
250-
path=pstrdup(p);/* make a modifiable copy */
251-
for (startp=path,endp=strchr(path,PATHSEP);
252-
startp&&*startp;
253-
startp=endp+1,endp=strchr(startp,PATHSEP))
241+
char*startp=NULL,*endp=NULL;
242+
243+
do
254244
{
255-
if (startp==endp)/* it's a "::" */
256-
continue;
257-
if (endp)
258-
*endp='\0';
245+
if (!startp)
246+
startp=path;
247+
else
248+
startp=endp+1;
259249

260-
if (is_absolute_path(startp))
261-
snprintf(retpath,MAXPGPATH,"%s/%s",startp,argv0);
250+
endp=strchr(startp,PATHSEP);
251+
if (!endp)
252+
endp=startp+strlen(startp);/* point to end */
253+
254+
StrNCpy(test_path,startp,Min(endp-startp+1,MAXPGPATH));
255+
256+
if (is_absolute_path(test_path))
257+
snprintf(retpath,MAXPGPATH,"%s/%s",test_path,argv0);
262258
else
263-
snprintf(retpath,MAXPGPATH,"%s/%s/%s",cwd,startp,argv0);
259+
snprintf(retpath,MAXPGPATH,"%s/%s/%s",cwd,test_path,argv0);
264260

265261
canonicalize_path(retpath);
266262
switch (validate_exec(retpath))
267263
{
268264
case0:/* found ok */
269265
win32_make_absolute(retpath);
270-
pfree(path);
271266
return0;
272267
case-1:/* wasn't even a candidate, keep looking */
273-
break;
268+
continue;
274269
case-2:/* found but disqualified */
275270
log_error("could not read binary \"%s\"",retpath);
276-
pfree(path);
277-
return-1;
271+
continue;
278272
}
279-
if (!endp)/* last one */
280-
break;
281-
}
282-
pfree(path);
273+
}while (*endp);
283274
}
284275

285276
log_error("could not find a \"%s\" to execute",argv0);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp