Skip to content

Commit dc94d4a

Browse files
committed
Remove xstrdup and friends who were only called once. Replace with
#ifdef calls.
1 parent 7dca975 commit dc94d4a

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/08 01:31:15 momjian Exp $
13+
* $PostgreSQL: pgsql/src/port/dirmod.c,v 1.16 2004/08/08 03: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
#define unlink(path) pgunlink(path)
236230
#endif
237231

238-
#ifdef FRONTEND
239-
240-
static void *
241-
xmalloc(size_t size)
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-
return result;
252-
}
253-
254-
static char *
255-
xstrdup(const char *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-
return result;
266-
}
267-
268-
#define xfree(n) free(n)
269-
270-
#else
271-
272-
/* on the backend, use palloc and friends */
273-
274-
#define xmalloc(n) palloc(n)
275-
#define xstrdup(n) pstrdup(n)
276-
#define xfree(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
static void
285238
rmt_cleanup(char ** filenames)
286239
{
287240
char ** fn;
288241

289242
for (fn = filenames; *fn; fn++)
290-
xfree(*fn);
243+
#ifdef FRONTEND
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+
#ifdef FRONTEND
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+
#ifdef FRONTEND
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)
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