[svn] Use alloca to allocate filename_plus_orig_suffix.

Published in <sxsu239htnl.fsf@florida.arsdigita.de>.
This commit is contained in:
hniksic 2001-04-28 09:36:46 -07:00
parent d70101ea4e
commit b44f1701b0
2 changed files with 12 additions and 21 deletions

View File

@ -1,3 +1,9 @@
2001-04-28 Hrvoje Niksic <hniksic@arsdigita.com>
(http_loop): Allocate space for filename_plus_orig_suffix with
alloca; this is more efficient and removes the need to free it
before each and every return.
2001-04-28 Hrvoje Niksic <hniksic@arsdigita.com> 2001-04-28 Hrvoje Niksic <hniksic@arsdigita.com>
* http.c (gethttp): Return RETRUNNEEDED when the retrieval is * http.c (gethttp): Return RETRUNNEEDED when the retrieval is

View File

@ -1402,11 +1402,8 @@ http_loop (struct urlinfo *u, char **newloc, int *dt)
else else
locf = opt.output_document; locf = opt.output_document;
/* Yuck. Multiple returns suck. We need to remember to free() the space we filename_len = strlen (u->local);
xmalloc() here before EACH return. This is one reason it's better to set filename_plus_orig_suffix = alloca (filename_len + sizeof (".orig"));
flags that influence flow control and then return once at the end. */
filename_len = strlen(u->local);
filename_plus_orig_suffix = xmalloc(filename_len + sizeof(".orig"));
if (opt.noclobber && file_exists_p (u->local)) if (opt.noclobber && file_exists_p (u->local))
{ {
@ -1424,7 +1421,6 @@ File `%s' already there, will not retrieve.\n"), u->local);
&& (!strcmp (suf, "html") || !strcmp (suf, "htm"))) && (!strcmp (suf, "html") || !strcmp (suf, "htm")))
*dt |= TEXTHTML; *dt |= TEXTHTML;
xfree (suf); xfree (suf);
xfree (filename_plus_orig_suffix); /* must precede every return! */
/* Another harmless lie: */ /* Another harmless lie: */
return RETROK; return RETROK;
} }
@ -1452,11 +1448,12 @@ File `%s' already there, will not retrieve.\n"), u->local);
in url.c. Replacing sprintf with inline calls to in url.c. Replacing sprintf with inline calls to
strcpy() and long_to_string() made a difference. strcpy() and long_to_string() made a difference.
--hniksic */ --hniksic */
strcpy(filename_plus_orig_suffix, u->local); memcpy (filename_plus_orig_suffix, u->local, filename_len);
strcpy(filename_plus_orig_suffix + filename_len, ".orig"); memcpy (filename_plus_orig_suffix + filename_len,
".orig", sizeof (".orig"));
/* Try to stat() the .orig file. */ /* Try to stat() the .orig file. */
if (stat(filename_plus_orig_suffix, &st) == 0) if (stat (filename_plus_orig_suffix, &st) == 0)
{ {
local_dot_orig_file_exists = TRUE; local_dot_orig_file_exists = TRUE;
local_filename = filename_plus_orig_suffix; local_filename = filename_plus_orig_suffix;
@ -1573,7 +1570,6 @@ File `%s' already there, will not retrieve.\n"), u->local);
case SSLERRCTXCREATE: case CONTNOTSUPPORTED: case SSLERRCTXCREATE: case CONTNOTSUPPORTED:
/* Fatal errors just return from the function. */ /* Fatal errors just return from the function. */
FREEHSTAT (hstat); FREEHSTAT (hstat);
xfree (filename_plus_orig_suffix); /* must precede every return! */
return err; return err;
break; break;
case FWRITEERR: case FOPENERR: case FWRITEERR: case FOPENERR:
@ -1589,7 +1585,6 @@ File `%s' already there, will not retrieve.\n"), u->local);
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logprintf (LOG_NOTQUIET, _("Unable to establish SSL connection.\n")); logprintf (LOG_NOTQUIET, _("Unable to establish SSL connection.\n"));
FREEHSTAT (hstat); FREEHSTAT (hstat);
xfree (filename_plus_orig_suffix); /* must precede every return! */
return err; return err;
break; break;
case NEWLOCATION: case NEWLOCATION:
@ -1599,17 +1594,14 @@ File `%s' already there, will not retrieve.\n"), u->local);
logprintf (LOG_NOTQUIET, logprintf (LOG_NOTQUIET,
_("ERROR: Redirection (%d) without location.\n"), _("ERROR: Redirection (%d) without location.\n"),
hstat.statcode); hstat.statcode);
xfree (filename_plus_orig_suffix); /* must precede every return! */
return WRONGCODE; return WRONGCODE;
} }
FREEHSTAT (hstat); FREEHSTAT (hstat);
xfree (filename_plus_orig_suffix); /* must precede every return! */
return NEWLOCATION; return NEWLOCATION;
break; break;
case RETRUNNEEDED: case RETRUNNEEDED:
/* The file was already fully retrieved. */ /* The file was already fully retrieved. */
FREEHSTAT (hstat); FREEHSTAT (hstat);
xfree (filename_plus_orig_suffix); /* must precede every return! */
return RETROK; return RETROK;
break; break;
case RETRFINISHED: case RETRFINISHED:
@ -1632,7 +1624,6 @@ File `%s' already there, will not retrieve.\n"), u->local);
tms, hstat.statcode, hstat.error); tms, hstat.statcode, hstat.error);
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
FREEHSTAT (hstat); FREEHSTAT (hstat);
xfree (filename_plus_orig_suffix); /* must precede every return! */
return WRONGCODE; return WRONGCODE;
} }
@ -1676,7 +1667,6 @@ Last-modified header invalid -- time-stamp ignored.\n"));
Server file no newer than local file `%s' -- not retrieving.\n\n"), Server file no newer than local file `%s' -- not retrieving.\n\n"),
local_filename); local_filename);
FREEHSTAT (hstat); FREEHSTAT (hstat);
xfree (filename_plus_orig_suffix); /*must precede every return!*/
return RETROK; return RETROK;
} }
else if (tml >= tmr) else if (tml >= tmr)
@ -1714,7 +1704,6 @@ The sizes do not match (local %ld) -- retrieving.\n"), local_size);
if (opt.spider) if (opt.spider)
{ {
logprintf (LOG_NOTQUIET, "%d %s\n\n", hstat.statcode, hstat.error); logprintf (LOG_NOTQUIET, "%d %s\n\n", hstat.statcode, hstat.error);
xfree (filename_plus_orig_suffix); /* must precede every return! */
return RETROK; return RETROK;
} }
@ -1744,7 +1733,6 @@ The sizes do not match (local %ld) -- retrieving.\n"), local_size);
else else
downloaded_file(FILE_DOWNLOADED_NORMALLY, locf); downloaded_file(FILE_DOWNLOADED_NORMALLY, locf);
xfree(filename_plus_orig_suffix); /* must precede every return! */
return RETROK; return RETROK;
} }
else if (hstat.res == 0) /* No read error */ else if (hstat.res == 0) /* No read error */
@ -1770,7 +1758,6 @@ The sizes do not match (local %ld) -- retrieving.\n"), local_size);
else else
downloaded_file(FILE_DOWNLOADED_NORMALLY, locf); downloaded_file(FILE_DOWNLOADED_NORMALLY, locf);
xfree (filename_plus_orig_suffix); /* must precede every return! */
return RETROK; return RETROK;
} }
else if (hstat.len < hstat.contlen) /* meaning we lost the else if (hstat.len < hstat.contlen) /* meaning we lost the
@ -1799,7 +1786,6 @@ The sizes do not match (local %ld) -- retrieving.\n"), local_size);
else else
downloaded_file(FILE_DOWNLOADED_NORMALLY, locf); downloaded_file(FILE_DOWNLOADED_NORMALLY, locf);
xfree (filename_plus_orig_suffix); /* must precede every return! */
return RETROK; return RETROK;
} }
else /* the same, but not accepted */ else /* the same, but not accepted */
@ -1835,7 +1821,6 @@ The sizes do not match (local %ld) -- retrieving.\n"), local_size);
break; break;
} }
while (!opt.ntry || (count < opt.ntry)); while (!opt.ntry || (count < opt.ntry));
xfree (filename_plus_orig_suffix); /* must precede every return! */
return TRYLIMEXC; return TRYLIMEXC;
} }