mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
replaced read_whole_file() by getline()
This commit is contained in:
parent
e976d4f3dc
commit
099d8ee3da
@ -1,3 +1,18 @@
|
|||||||
|
2013-05-14 Tim Ruehsen <tim.ruehsen@gmx.de>
|
||||||
|
|
||||||
|
* cookies.c (cookie_jar_load): Replaced read_whole_file() by getline().
|
||||||
|
* init.c (run_wgetrc): Likewise.
|
||||||
|
* netrc.c (parse_netrc): Likewise.
|
||||||
|
* utils.c: Likewise.
|
||||||
|
* ftp.c (getftp): Likewise.
|
||||||
|
* ftp-ls.c (ftp_parse_unix_ls, ftp_parse_winnt_ls, ftp_parse_vms_ls): Likewise.
|
||||||
|
* ftp-ls.c (clean_line): Accept the string length as parameter.
|
||||||
|
* ftp-ls.c: Replaced indent tabs by spaces.
|
||||||
|
* ftp.c: Likewise.
|
||||||
|
* utils.c: Removed read_whole_file() definition.
|
||||||
|
* netrc.c: Removed read_whole_file() definition for STANDALONE.
|
||||||
|
* utils.h: Removed read_whole_file() declaration.
|
||||||
|
|
||||||
2013-05-09 Tim Ruehsen <tim.ruehsen@gmx.de>
|
2013-05-09 Tim Ruehsen <tim.ruehsen@gmx.de>
|
||||||
|
|
||||||
* utils.c (acceptable): use standard string functions instead of
|
* utils.c (acceptable): use standard string functions instead of
|
||||||
|
@ -1129,7 +1129,9 @@ domain_port (const char *domain_b, const char *domain_e,
|
|||||||
void
|
void
|
||||||
cookie_jar_load (struct cookie_jar *jar, const char *file)
|
cookie_jar_load (struct cookie_jar *jar, const char *file)
|
||||||
{
|
{
|
||||||
char *line;
|
char *line = NULL;
|
||||||
|
size_t bufsize = 0;
|
||||||
|
|
||||||
FILE *fp = fopen (file, "r");
|
FILE *fp = fopen (file, "r");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
{
|
{
|
||||||
@ -1137,9 +1139,10 @@ cookie_jar_load (struct cookie_jar *jar, const char *file)
|
|||||||
quote (file), strerror (errno));
|
quote (file), strerror (errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cookies_now = time (NULL);
|
cookies_now = time (NULL);
|
||||||
|
|
||||||
for (; ((line = read_whole_line (fp)) != NULL); xfree (line))
|
while (getline (&line, &bufsize, fp) > 0)
|
||||||
{
|
{
|
||||||
struct cookie *cookie;
|
struct cookie *cookie;
|
||||||
char *p = line;
|
char *p = line;
|
||||||
@ -1233,6 +1236,8 @@ cookie_jar_load (struct cookie_jar *jar, const char *file)
|
|||||||
abort_cookie:
|
abort_cookie:
|
||||||
delete_cookie (cookie);
|
delete_cookie (cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xfree(line);
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
120
src/ftp-ls.c
120
src/ftp-ls.c
@ -68,16 +68,17 @@ symperms (const char *s)
|
|||||||
replaces all <TAB> character with <SPACE>. Returns the length of the
|
replaces all <TAB> character with <SPACE>. Returns the length of the
|
||||||
modified line. */
|
modified line. */
|
||||||
static int
|
static int
|
||||||
clean_line(char *line)
|
clean_line (char *line, int len)
|
||||||
{
|
{
|
||||||
int len = strlen (line);
|
if (len <= 0) return 0;
|
||||||
if (!len) return 0;
|
|
||||||
if (line[len - 1] == '\n')
|
while (len > 0 && (line[len - 1] == '\n' || line[len - 1] == '\r'))
|
||||||
line[--len] = '\0';
|
line[--len] = '\0';
|
||||||
|
|
||||||
if (!len) return 0;
|
if (!len) return 0;
|
||||||
if (line[len - 1] == '\r')
|
|
||||||
line[--len] = '\0';
|
|
||||||
for ( ; *line ; line++ ) if (*line == '\t') *line = ' ';
|
for ( ; *line ; line++ ) if (*line == '\t') *line = ' ';
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,8 +103,9 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
|
|||||||
int hour, min, sec, ptype;
|
int hour, min, sec, ptype;
|
||||||
struct tm timestruct, *tnow;
|
struct tm timestruct, *tnow;
|
||||||
time_t timenow;
|
time_t timenow;
|
||||||
|
size_t bufsize = 0;
|
||||||
|
|
||||||
char *line, *tok, *ptok; /* tokenizer */
|
char *line = NULL, *tok, *ptok; /* tokenizer */
|
||||||
struct fileinfo *dir, *l, cur; /* list creation */
|
struct fileinfo *dir, *l, cur; /* list creation */
|
||||||
|
|
||||||
fp = fopen (file, "rb");
|
fp = fopen (file, "rb");
|
||||||
@ -115,22 +117,16 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
|
|||||||
dir = l = NULL;
|
dir = l = NULL;
|
||||||
|
|
||||||
/* Line loop to end of file: */
|
/* Line loop to end of file: */
|
||||||
while ((line = read_whole_line (fp)) != NULL)
|
while ((len = getline (&line, &bufsize, fp)) > 0)
|
||||||
{
|
{
|
||||||
len = clean_line (line);
|
len = clean_line (line, len);
|
||||||
/* Skip if total... */
|
/* Skip if total... */
|
||||||
if (!strncasecmp (line, "total", 5))
|
if (!strncasecmp (line, "total", 5))
|
||||||
{
|
|
||||||
xfree (line);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
/* Get the first token (permissions). */
|
/* Get the first token (permissions). */
|
||||||
tok = strtok (line, " ");
|
tok = strtok (line, " ");
|
||||||
if (!tok)
|
if (!tok)
|
||||||
{
|
|
||||||
xfree (line);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
cur.name = NULL;
|
cur.name = NULL;
|
||||||
cur.linkto = NULL;
|
cur.linkto = NULL;
|
||||||
@ -368,7 +364,6 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
|
|||||||
DEBUGP (("Skipping.\n"));
|
DEBUGP (("Skipping.\n"));
|
||||||
xfree_null (cur.name);
|
xfree_null (cur.name);
|
||||||
xfree_null (cur.linkto);
|
xfree_null (cur.linkto);
|
||||||
xfree (line);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,10 +411,9 @@ ftp_parse_unix_ls (const char *file, int ignore_perms)
|
|||||||
timestruct.tm_isdst = -1;
|
timestruct.tm_isdst = -1;
|
||||||
l->tstamp = mktime (×truct); /* store the time-stamp */
|
l->tstamp = mktime (×truct); /* store the time-stamp */
|
||||||
l->ptype = ptype;
|
l->ptype = ptype;
|
||||||
|
|
||||||
xfree (line);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xfree (line);
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
@ -431,9 +425,10 @@ ftp_parse_winnt_ls (const char *file)
|
|||||||
int len;
|
int len;
|
||||||
int year, month, day; /* for time analysis */
|
int year, month, day; /* for time analysis */
|
||||||
int hour, min;
|
int hour, min;
|
||||||
|
size_t bufsize = 0;
|
||||||
struct tm timestruct;
|
struct tm timestruct;
|
||||||
|
|
||||||
char *line, *tok; /* tokenizer */
|
char *line = NULL, *tok; /* tokenizer */
|
||||||
char *filename;
|
char *filename;
|
||||||
struct fileinfo *dir, *l, cur; /* list creation */
|
struct fileinfo *dir, *l, cur; /* list creation */
|
||||||
|
|
||||||
@ -446,29 +441,29 @@ ftp_parse_winnt_ls (const char *file)
|
|||||||
dir = l = NULL;
|
dir = l = NULL;
|
||||||
|
|
||||||
/* Line loop to end of file: */
|
/* Line loop to end of file: */
|
||||||
while ((line = read_whole_line (fp)) != NULL)
|
while ((len = getline (&line, &bufsize, fp)) > 0)
|
||||||
{
|
{
|
||||||
len = clean_line (line);
|
len = clean_line (line, len);
|
||||||
|
|
||||||
/* Name begins at 39 column of the listing if date presented in `mm-dd-yy'
|
/* Name begins at 39 column of the listing if date presented in `mm-dd-yy'
|
||||||
format or at 41 column if date presented in `mm-dd-yyyy' format. Thus,
|
format or at 41 column if date presented in `mm-dd-yyyy' format. Thus,
|
||||||
we cannot extract name before we parse date. Using this information we
|
we cannot extract name before we parse date. Using this information we
|
||||||
also can recognize filenames that begin with a series of space
|
also can recognize filenames that begin with a series of space
|
||||||
characters (but who really wants to use such filenames anyway?). */
|
characters (but who really wants to use such filenames anyway?). */
|
||||||
if (len < 40) goto continue_loop;
|
if (len < 40) continue;
|
||||||
filename = line + 39;
|
filename = line + 39;
|
||||||
|
|
||||||
/* First column: mm-dd-yy or mm-dd-yyyy. Should atoi() on the month fail,
|
/* First column: mm-dd-yy or mm-dd-yyyy. Should atoi() on the month fail,
|
||||||
january will be assumed. */
|
january will be assumed. */
|
||||||
tok = strtok(line, "-");
|
tok = strtok(line, "-");
|
||||||
if (tok == NULL) goto continue_loop;
|
if (tok == NULL) continue;
|
||||||
month = atoi(tok) - 1;
|
month = atoi(tok) - 1;
|
||||||
if (month < 0) month = 0;
|
if (month < 0) month = 0;
|
||||||
tok = strtok(NULL, "-");
|
tok = strtok(NULL, "-");
|
||||||
if (tok == NULL) goto continue_loop;
|
if (tok == NULL) continue;
|
||||||
day = atoi(tok);
|
day = atoi(tok);
|
||||||
tok = strtok(NULL, " ");
|
tok = strtok(NULL, " ");
|
||||||
if (tok == NULL) goto continue_loop;
|
if (tok == NULL) continue;
|
||||||
year = atoi(tok);
|
year = atoi(tok);
|
||||||
/* Assuming the epoch starting at 1.1.1970 */
|
/* Assuming the epoch starting at 1.1.1970 */
|
||||||
if (year <= 70)
|
if (year <= 70)
|
||||||
@ -489,10 +484,10 @@ ftp_parse_winnt_ls (const char *file)
|
|||||||
/* Second column: hh:mm[AP]M, listing does not contain value for
|
/* Second column: hh:mm[AP]M, listing does not contain value for
|
||||||
seconds */
|
seconds */
|
||||||
tok = strtok(NULL, ":");
|
tok = strtok(NULL, ":");
|
||||||
if (tok == NULL) goto continue_loop;
|
if (tok == NULL) continue;
|
||||||
hour = atoi(tok);
|
hour = atoi(tok);
|
||||||
tok = strtok(NULL, "M");
|
tok = strtok(NULL, "M");
|
||||||
if (tok == NULL) goto continue_loop;
|
if (tok == NULL) continue;
|
||||||
min = atoi(tok);
|
min = atoi(tok);
|
||||||
/* Adjust hour from AM/PM. Just for the record, the sequence goes
|
/* Adjust hour from AM/PM. Just for the record, the sequence goes
|
||||||
11:00AM, 12:00PM, 01:00PM ... 11:00PM, 12:00AM, 01:00AM . */
|
11:00AM, 12:00PM, 01:00PM ... 11:00PM, 12:00AM, 01:00AM . */
|
||||||
@ -523,9 +518,9 @@ ftp_parse_winnt_ls (const char *file)
|
|||||||
directories as the listing does not give us a clue) and filetype
|
directories as the listing does not give us a clue) and filetype
|
||||||
here. */
|
here. */
|
||||||
tok = strtok(NULL, " ");
|
tok = strtok(NULL, " ");
|
||||||
if (tok == NULL) goto continue_loop;
|
if (tok == NULL) continue;
|
||||||
while ((tok != NULL) && (*tok == '\0')) tok = strtok(NULL, " ");
|
while ((tok != NULL) && (*tok == '\0')) tok = strtok(NULL, " ");
|
||||||
if (tok == NULL) goto continue_loop;
|
if (tok == NULL) continue;
|
||||||
if (*tok == '<')
|
if (*tok == '<')
|
||||||
{
|
{
|
||||||
cur.type = FT_DIRECTORY;
|
cur.type = FT_DIRECTORY;
|
||||||
@ -564,11 +559,9 @@ ftp_parse_winnt_ls (const char *file)
|
|||||||
memcpy (l, &cur, sizeof (cur));
|
memcpy (l, &cur, sizeof (cur));
|
||||||
l->next = NULL;
|
l->next = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
continue_loop:
|
|
||||||
xfree (line);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xfree (line);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
@ -689,11 +682,12 @@ ftp_parse_vms_ls (const char *file)
|
|||||||
FILE *fp;
|
FILE *fp;
|
||||||
int dt, i, j, len;
|
int dt, i, j, len;
|
||||||
int perms;
|
int perms;
|
||||||
|
size_t bufsize = 0;
|
||||||
time_t timenow;
|
time_t timenow;
|
||||||
struct tm *timestruct;
|
struct tm *timestruct;
|
||||||
char date_str[ 32];
|
char date_str[ 32];
|
||||||
|
|
||||||
char *line, *tok; /* tokenizer */
|
char *line = NULL, *tok; /* tokenizer */
|
||||||
struct fileinfo *dir, *l, cur; /* list creation */
|
struct fileinfo *dir, *l, cur; /* list creation */
|
||||||
|
|
||||||
fp = fopen (file, "r");
|
fp = fopen (file, "r");
|
||||||
@ -706,38 +700,23 @@ ftp_parse_vms_ls (const char *file)
|
|||||||
|
|
||||||
/* Skip blank lines, Directory heading, and more blank lines. */
|
/* Skip blank lines, Directory heading, and more blank lines. */
|
||||||
|
|
||||||
j = 0; /* Expecting initial blank line(s). */
|
for (j = 0; (i = getline (&line, &bufsize, fp)) > 0; )
|
||||||
while (1)
|
|
||||||
{
|
{
|
||||||
line = read_whole_line (fp);
|
i = clean_line (line, i);
|
||||||
if (line == NULL)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i = clean_line (line);
|
|
||||||
if (i <= 0)
|
if (i <= 0)
|
||||||
{
|
continue; /* Ignore blank line. */
|
||||||
xfree (line); /* Free useless line storage. */
|
|
||||||
continue; /* Blank line. Keep looking. */
|
if ((j == 0) && (line[i - 1] == ']'))
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ((j == 0) && (line[ i- 1] == ']'))
|
|
||||||
{
|
{
|
||||||
/* Found Directory heading line. Next non-blank line
|
/* Found Directory heading line. Next non-blank line
|
||||||
is significant.
|
is significant. */
|
||||||
*/
|
|
||||||
j = 1;
|
j = 1;
|
||||||
}
|
}
|
||||||
else if (!strncmp (line, "Total of ", 9))
|
else if (!strncmp (line, "Total of ", 9))
|
||||||
{
|
{
|
||||||
/* Found "Total of ..." footing line. No valid data
|
/* Found "Total of ..." footing line. No valid data
|
||||||
will follow (empty directory).
|
will follow (empty directory). */
|
||||||
*/
|
i = 0; /* Arrange for early exit. */
|
||||||
xfree (line); /* Free useless line storage. */
|
|
||||||
line = NULL; /* Arrange for early exit. */
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -745,13 +724,10 @@ ftp_parse_vms_ls (const char *file)
|
|||||||
break; /* Must be significant data. */
|
break; /* Must be significant data. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xfree (line); /* Free useless line storage. */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read remainder of file until the next blank line or EOF. */
|
/* Read remainder of file until the next blank line or EOF. */
|
||||||
|
|
||||||
while (line != NULL)
|
while (i > 0)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
@ -842,9 +818,8 @@ ftp_parse_vms_ls (const char *file)
|
|||||||
if (tok == NULL)
|
if (tok == NULL)
|
||||||
{
|
{
|
||||||
DEBUGP (("Getting additional line.\n"));
|
DEBUGP (("Getting additional line.\n"));
|
||||||
xfree (line);
|
i = getline (&line, &bufsize, fp);
|
||||||
line = read_whole_line (fp);
|
if (i <= 0)
|
||||||
if (!line)
|
|
||||||
{
|
{
|
||||||
DEBUGP (("EOF. Leaving listing parser.\n"));
|
DEBUGP (("EOF. Leaving listing parser.\n"));
|
||||||
break;
|
break;
|
||||||
@ -853,14 +828,14 @@ ftp_parse_vms_ls (const char *file)
|
|||||||
/* Second line must begin with " ". Otherwise, it's a first
|
/* Second line must begin with " ". Otherwise, it's a first
|
||||||
line (and we may be confused).
|
line (and we may be confused).
|
||||||
*/
|
*/
|
||||||
|
i = clean_line (line, i);
|
||||||
if (i <= 0)
|
if (i <= 0)
|
||||||
{
|
{
|
||||||
/* Blank line. End of significant file listing. */
|
/* Blank line. End of significant file listing. */
|
||||||
DEBUGP (("Blank line. Leaving listing parser.\n"));
|
DEBUGP (("Blank line. Leaving listing parser.\n"));
|
||||||
xfree (line); /* Free useless line storage. */
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (line[ 0] != ' ')
|
else if (line[0] != ' ')
|
||||||
{
|
{
|
||||||
DEBUGP (("Non-blank in column 1. Must be a new file name?\n"));
|
DEBUGP (("Non-blank in column 1. Must be a new file name?\n"));
|
||||||
continue;
|
continue;
|
||||||
@ -872,7 +847,6 @@ ftp_parse_vms_ls (const char *file)
|
|||||||
{
|
{
|
||||||
/* Unexpected non-empty but apparently blank line. */
|
/* Unexpected non-empty but apparently blank line. */
|
||||||
DEBUGP (("Null token. Leaving listing parser.\n"));
|
DEBUGP (("Null token. Leaving listing parser.\n"));
|
||||||
xfree (line); /* Free useless line storage. */
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -911,7 +885,7 @@ ftp_parse_vms_ls (const char *file)
|
|||||||
(sizeof( date_str)- strlen (date_str) - 1));
|
(sizeof( date_str)- strlen (date_str) - 1));
|
||||||
DEBUGP (("Date time: >%s<\n", date_str));
|
DEBUGP (("Date time: >%s<\n", date_str));
|
||||||
}
|
}
|
||||||
else if (strchr ( tok, '[') != NULL)
|
else if (strchr (tok, '[') != NULL)
|
||||||
{
|
{
|
||||||
/* Owner. (Ignore.) */
|
/* Owner. (Ignore.) */
|
||||||
DEBUGP (("Owner.\n"));
|
DEBUGP (("Owner.\n"));
|
||||||
@ -921,7 +895,7 @@ ftp_parse_vms_ls (const char *file)
|
|||||||
/* Protections (permissions). */
|
/* Protections (permissions). */
|
||||||
perms = 0;
|
perms = 0;
|
||||||
j = 0;
|
j = 0;
|
||||||
for (i = 0; i < strlen( tok); i++)
|
for (i = 0; i < strlen(tok); i++)
|
||||||
{
|
{
|
||||||
switch (tok[ i])
|
switch (tok[ i])
|
||||||
{
|
{
|
||||||
@ -1015,21 +989,19 @@ ftp_parse_vms_ls (const char *file)
|
|||||||
l->next = NULL;
|
l->next = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free old line storage. Read a new line. */
|
i = getline (&line, &bufsize, fp);
|
||||||
xfree (line);
|
if (i > 0)
|
||||||
line = read_whole_line (fp);
|
|
||||||
if (line != NULL)
|
|
||||||
{
|
{
|
||||||
i = clean_line (line);
|
i = clean_line (line, i);
|
||||||
if (i <= 0)
|
if (i <= 0)
|
||||||
{
|
{
|
||||||
/* Blank line. End of significant file listing. */
|
/* Blank line. End of significant file listing. */
|
||||||
xfree (line); /* Free useless line storage. */
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xfree (line);
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
16
src/ftp.c
16
src/ftp.c
@ -1367,18 +1367,20 @@ Error in server response, closing control connection.\n"));
|
|||||||
logprintf (LOG_ALWAYS, "%s: %s\n", con->target, strerror (errno));
|
logprintf (LOG_ALWAYS, "%s: %s\n", con->target, strerror (errno));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char *line;
|
char *line = NULL;
|
||||||
/* The lines are being read with read_whole_line because of
|
size_t bufsize = 0;
|
||||||
|
ssize_t len;
|
||||||
|
|
||||||
|
/* The lines are being read with getline because of
|
||||||
no-buffering on opt.lfile. */
|
no-buffering on opt.lfile. */
|
||||||
while ((line = read_whole_line (fp)) != NULL)
|
while ((len = getline (&line, &bufsize, fp)) > 0)
|
||||||
{
|
{
|
||||||
char *p = strchr (line, '\0');
|
while (len > 0 && (line[len - 1] == '\n' || line[len - 1] == '\r'))
|
||||||
while (p > line && (p[-1] == '\n' || p[-1] == '\r'))
|
line[--len] = '\0';
|
||||||
*--p = '\0';
|
|
||||||
logprintf (LOG_ALWAYS, "%s\n",
|
logprintf (LOG_ALWAYS, "%s\n",
|
||||||
quotearg_style (escape_quoting_style, line));
|
quotearg_style (escape_quoting_style, line));
|
||||||
xfree (line);
|
|
||||||
}
|
}
|
||||||
|
xfree (line);
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
}
|
}
|
||||||
} /* con->cmd & DO_LIST && server_response */
|
} /* con->cmd & DO_LIST && server_response */
|
||||||
|
@ -574,7 +574,8 @@ bool
|
|||||||
run_wgetrc (const char *file)
|
run_wgetrc (const char *file)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *line;
|
char *line = NULL;
|
||||||
|
size_t bufsize = 0;
|
||||||
int ln;
|
int ln;
|
||||||
int errcnt = 0;
|
int errcnt = 0;
|
||||||
|
|
||||||
@ -586,7 +587,7 @@ run_wgetrc (const char *file)
|
|||||||
return true; /* not a fatal error */
|
return true; /* not a fatal error */
|
||||||
}
|
}
|
||||||
ln = 1;
|
ln = 1;
|
||||||
while ((line = read_whole_line (fp)) != NULL)
|
while (getline (&line, &bufsize, fp) > 0)
|
||||||
{
|
{
|
||||||
char *com = NULL, *val = NULL;
|
char *com = NULL, *val = NULL;
|
||||||
int comind;
|
int comind;
|
||||||
@ -620,9 +621,9 @@ run_wgetrc (const char *file)
|
|||||||
}
|
}
|
||||||
xfree_null (com);
|
xfree_null (com);
|
||||||
xfree_null (val);
|
xfree_null (val);
|
||||||
xfree (line);
|
|
||||||
++ln;
|
++ln;
|
||||||
}
|
}
|
||||||
|
xfree (line);
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
|
|
||||||
return errcnt == 0;
|
return errcnt == 0;
|
||||||
|
50
src/netrc.c
50
src/netrc.c
@ -164,48 +164,6 @@ search_netrc (const char *host, const char **acc, const char **passwd,
|
|||||||
|
|
||||||
# define xrealloc realloc
|
# define xrealloc realloc
|
||||||
|
|
||||||
/* Read a line from FP. The function reallocs the storage as needed
|
|
||||||
to accomodate for any length of the line. Reallocs are done
|
|
||||||
storage exponentially, doubling the storage after each overflow to
|
|
||||||
minimize the number of calls to realloc() and fgets(). The newline
|
|
||||||
character at the end of line is retained.
|
|
||||||
|
|
||||||
After end-of-file is encountered without anything being read, NULL
|
|
||||||
is returned. NULL is also returned on error. To distinguish
|
|
||||||
between these two cases, use the stdio function ferror(). */
|
|
||||||
|
|
||||||
char *
|
|
||||||
read_whole_line (FILE *fp)
|
|
||||||
{
|
|
||||||
int length = 0;
|
|
||||||
int bufsize = 81;
|
|
||||||
char *line = xmalloc (bufsize);
|
|
||||||
|
|
||||||
while (fgets (line + length, bufsize - length, fp))
|
|
||||||
{
|
|
||||||
length += strlen (line + length);
|
|
||||||
assert (length > 0);
|
|
||||||
if (line[length - 1] == '\n')
|
|
||||||
break;
|
|
||||||
/* fgets() guarantees to read the whole line, or to use up the
|
|
||||||
space we've given it. We can double the buffer
|
|
||||||
unconditionally. */
|
|
||||||
bufsize <<= 1;
|
|
||||||
line = xrealloc (line, bufsize);
|
|
||||||
}
|
|
||||||
if (length == 0 || ferror (fp))
|
|
||||||
{
|
|
||||||
xfree (line);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (length + 1 < bufsize)
|
|
||||||
/* Relieve the memory from our exponential greediness. We say
|
|
||||||
`length + 1' because the terminating \0 is not included in
|
|
||||||
LENGTH. We don't need to zero-terminate the string ourselves,
|
|
||||||
though, because fgets() does that. */
|
|
||||||
line = xrealloc (line, length + 1);
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
#endif /* STANDALONE */
|
#endif /* STANDALONE */
|
||||||
|
|
||||||
/* Maybe add NEWENTRY to the account information list, LIST. NEWENTRY is
|
/* Maybe add NEWENTRY to the account information list, LIST. NEWENTRY is
|
||||||
@ -264,10 +222,11 @@ static acc_t *
|
|||||||
parse_netrc (const char *path)
|
parse_netrc (const char *path)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *line, *p, *tok;
|
char *line = NULL, *p, *tok;
|
||||||
const char *premature_token;
|
const char *premature_token;
|
||||||
acc_t *current, *retval;
|
acc_t *current, *retval;
|
||||||
int ln, qmark;
|
int ln, qmark;
|
||||||
|
size_t bufsize = 0;
|
||||||
|
|
||||||
/* The latest token we've seen in the file. */
|
/* The latest token we've seen in the file. */
|
||||||
enum
|
enum
|
||||||
@ -290,7 +249,7 @@ parse_netrc (const char *path)
|
|||||||
premature_token = NULL;
|
premature_token = NULL;
|
||||||
|
|
||||||
/* While there are lines in the file... */
|
/* While there are lines in the file... */
|
||||||
while ((line = read_whole_line (fp)) != NULL)
|
while (getline (&line, &bufsize, fp) > 0)
|
||||||
{
|
{
|
||||||
ln ++;
|
ln ++;
|
||||||
|
|
||||||
@ -423,10 +382,9 @@ parse_netrc (const char *path)
|
|||||||
exec_name, path, ln, tok);
|
exec_name, path, ln, tok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xfree (line);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xfree (line);
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
|
|
||||||
/* Finalize the last machine entry we found. */
|
/* Finalize the last machine entry we found. */
|
||||||
|
50
src/utils.c
50
src/utils.c
@ -1118,56 +1118,6 @@ has_html_suffix_p (const char *fname)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read a line from FP and return the pointer to freshly allocated
|
|
||||||
storage. The storage space is obtained through malloc() and should
|
|
||||||
be freed with free() when it is no longer needed.
|
|
||||||
|
|
||||||
The length of the line is not limited, except by available memory.
|
|
||||||
The newline character at the end of line is retained. The line is
|
|
||||||
terminated with a zero character.
|
|
||||||
|
|
||||||
After end-of-file is encountered without anything being read, NULL
|
|
||||||
is returned. NULL is also returned on error. To distinguish
|
|
||||||
between these two cases, use the stdio function ferror(). */
|
|
||||||
|
|
||||||
char *
|
|
||||||
read_whole_line (FILE *fp)
|
|
||||||
{
|
|
||||||
int length = 0;
|
|
||||||
int bufsize = 82;
|
|
||||||
char *line = xmalloc (bufsize);
|
|
||||||
|
|
||||||
while (fgets (line + length, bufsize - length, fp))
|
|
||||||
{
|
|
||||||
length += strlen (line + length);
|
|
||||||
if (length == 0)
|
|
||||||
/* Possible for example when reading from a binary file where
|
|
||||||
a line begins with \0. */
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (line[length - 1] == '\n')
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* fgets() guarantees to read the whole line, or to use up the
|
|
||||||
space we've given it. We can double the buffer
|
|
||||||
unconditionally. */
|
|
||||||
bufsize <<= 1;
|
|
||||||
line = xrealloc (line, bufsize);
|
|
||||||
}
|
|
||||||
if (length == 0 || ferror (fp))
|
|
||||||
{
|
|
||||||
xfree (line);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (length + 1 < bufsize)
|
|
||||||
/* Relieve the memory from our exponential greediness. We say
|
|
||||||
`length + 1' because the terminating \0 is not included in
|
|
||||||
LENGTH. We don't need to zero-terminate the string ourselves,
|
|
||||||
though, because fgets() does that. */
|
|
||||||
line = xrealloc (line, length + 1);
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read FILE into memory. A pointer to `struct file_memory' are
|
/* Read FILE into memory. A pointer to `struct file_memory' are
|
||||||
returned; use struct element `content' to access file contents, and
|
returned; use struct element `content' to access file contents, and
|
||||||
the element `length' to know the file length. `content' is *not*
|
the element `length' to know the file length. `content' is *not*
|
||||||
|
@ -98,7 +98,6 @@ bool has_wildcards_p (const char *);
|
|||||||
|
|
||||||
bool has_html_suffix_p (const char *);
|
bool has_html_suffix_p (const char *);
|
||||||
|
|
||||||
char *read_whole_line (FILE *);
|
|
||||||
struct file_memory *wget_read_file (const char *);
|
struct file_memory *wget_read_file (const char *);
|
||||||
void wget_read_file_free (struct file_memory *);
|
void wget_read_file_free (struct file_memory *);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user