outfile parsing.

This commit is contained in:
Kelvin Sherlock 2012-04-28 00:35:51 -04:00
parent 2903af5f60
commit 62754f7431
1 changed files with 19 additions and 17 deletions

View File

@ -268,6 +268,7 @@ int do_gopher(const char *url, URLComponents *components)
host = URLComponentGetCMalloc(url, components, URLComponentHost);
path = URLComponentGetCMalloc(url, components, URLComponentPath);
if (!host)
{
fprintf(stderr, "URL `%s': no host.", url);
@ -294,22 +295,12 @@ int do_gopher(const char *url, URLComponents *components)
if (flags._O)
{
if (!path)
if (path)
{
fprintf(stderr, "-O flag cannot be used with this URL.\n");
return -1;
}
filename = strrchr(path + 2, '/');
if (filename) // *filename == '/'
{
filename++;
if (!filename[0])
{
// path/ ?
fprintf(stderr, "-O flag cannot be used with this URL.\n");
return -1;
}
}
else
{
@ -317,6 +308,17 @@ int do_gopher(const char *url, URLComponents *components)
}
}
if (!filename || !filename[0])
{
// path/ ?
fprintf(stderr, "-O flag cannot be used with this URL.\n");
free(host);
free(path);
return -1;
}
}
if (filename)
{
file = fopen(filename, "w");