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

Commitdc94d4a

Browse files
committed
Remove xstrdup and friends who were only called once. Replace with
#ifdef calls.
1 parent7dca975 commitdc94d4a

File tree

1 file changed

+33
-56
lines changed

1 file changed

+33
-56
lines changed

‎src/port/dirmod.c

Lines changed: 33 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*Win32 (NT, Win2k, XP).replace() doesn't work on Win95/98/Me.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/port/dirmod.c,v 1.15 2004/08/0801:31:15 momjian Exp $
13+
* $PostgreSQL: pgsql/src/port/dirmod.c,v 1.16 2004/08/0803:51:20 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -224,74 +224,34 @@ pgsymlink(const char *oldpath, const char *newpath)
224224
#endif
225225

226226

227-
/* ----------------
228-
*rmtree routines
229-
* ----------------
230-
*/
231-
232-
233-
/* We undefined these above, so we redefine them */
227+
/* We undefined this above, so we redefine it */
234228
#if defined(WIN32)|| defined(__CYGWIN__)
235229
#defineunlink(path)pgunlink(path)
236230
#endif
237231

238-
#ifdefFRONTEND
239-
240-
staticvoid*
241-
xmalloc(size_tsize)
242-
{
243-
void*result;
244-
245-
result=malloc(size);
246-
if (!result)
247-
{
248-
fprintf(stderr,_("out of memory\n"));
249-
exit(1);
250-
}
251-
returnresult;
252-
}
253-
254-
staticchar*
255-
xstrdup(constchar*s)
256-
{
257-
char*result;
258-
259-
result=strdup(s);
260-
if (!result)
261-
{
262-
fprintf(stderr,_("out of memory\n"));
263-
exit(1);
264-
}
265-
returnresult;
266-
}
267-
268-
#definexfree(n) free(n)
269-
270-
#else
271-
272-
/* on the backend, use palloc and friends */
273-
274-
#definexmalloc(n)palloc(n)
275-
#definexstrdup(n)pstrdup(n)
276-
#definexfree(n)pfree(n)
277-
278-
#endif
279-
280232
/*
281-
* deallocate memory used for filenames
233+
*rmt_cleanup
234+
*
235+
*deallocate memory used for filenames
282236
*/
283-
284237
staticvoid
285238
rmt_cleanup(char**filenames)
286239
{
287240
char**fn;
288241

289242
for (fn=filenames;*fn;fn++)
290-
xfree(*fn);
243+
#ifdefFRONTEND
244+
free(*fn);
245+
246+
free(filenames);
247+
#else
248+
pfree(*fn);
291249

292-
xfree(filenames);
250+
pfree(filenames);
251+
#endif
293252
}
294253

254+
295255
/*
296256
*rmtree
297257
*
@@ -329,13 +289,30 @@ rmtree(char *path, bool rmtopdir)
329289

330290
rewinddir(dir);
331291

332-
filenames=xmalloc((numnames+2)*sizeof(char*));
292+
#ifdefFRONTEND
293+
if ((filenames=malloc((numnames+2)*sizeof(char*)))==NULL)
294+
{
295+
fprintf(stderr,_("out of memory\n"));
296+
exit(1);
297+
}
298+
#else
299+
filenames=palloc((numnames+2)*sizeof(char*));
300+
#endif
301+
333302
numnames=0;
334303

335304
while ((file=readdir(dir))!=NULL)
336305
{
337306
if (strcmp(file->d_name,".")!=0&&strcmp(file->d_name,"..")!=0)
338-
filenames[numnames++]=xstrdup(file->d_name);
307+
#ifdefFRONTEND
308+
if ((filenames[numnames++]=strdup(file->d_name))==NULL)
309+
{
310+
fprintf(stderr,_("out of memory\n"));
311+
exit(1);
312+
}
313+
#else
314+
filenames[numnames++]=pstrdup(file->d_name);
315+
#endif
339316
}
340317

341318
filenames[numnames]=NULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp