summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2000-03-16 11:43:10 +0000
committerDaniel Stenberg <daniel@haxx.se>2000-03-16 11:43:10 +0000
commite3ef8b66a185a2982a7812ab19d2ee9970cb610f (patch)
tree47301ad18444e5ee833e47f8f92d9cea7e5a4392
parent739b3f241d10cc4e074ab1102c50f319d0378260 (diff)
downloadcurl-e3ef8b66a185a2982a7812ab19d2ee9970cb610f.tar.gz
the --dump-header option now only creates the file when it needs to, not any
sooner
-rw-r--r--src/main.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c
index ca1f4e2d3..a6bf56bb6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -859,6 +859,7 @@ int main(int argc, char *argv[])
char errorbuffer[URLGET_ERROR_SIZE];
struct OutStruct outs;
+ struct OutStruct heads;
char *url = NULL;
#ifdef GLOBURL
@@ -1086,14 +1087,12 @@ int main(int argc, char *argv[])
/* open file for output: */
if(strcmp(config.headerfile,"-"))
{
- headerfilep=(FILE *) fopen(config.headerfile, "wb");
- if (!headerfilep) {
- helpf("Can't open '%s'!\n", config.headerfile);
- return URG_WRITE_ERROR;
- }
+ heads.filename = config.headerfile;
+ headerfilep=NULL;
}
else
headerfilep=stdout;
+ heads.stream = headerfilep;
}
if(outs.stream && isatty(fileno(outs.stream)) &&
@@ -1147,7 +1146,7 @@ int main(int argc, char *argv[])
URGTAG_CRLF, config.crlf,
URGTAG_QUOTE, config.quote,
URGTAG_POSTQUOTE, config.postquote,
- URGTAG_WRITEHEADER, headerfilep,
+ URGTAG_WRITEHEADER, &heads,
URGTAG_COOKIEFILE, config.cookiefile,
URGTAG_SSLVERSION, config.ssl_version,
URGTAG_TIMECONDITION, config.timecond,
@@ -1165,6 +1164,9 @@ int main(int argc, char *argv[])
/* it wasn't directed to stdout or stderr so close the file! */
fclose(config.errors);
+ if(!headerfilep && heads.stream)
+ fclose(heads.stream);
+
if(urlbuffer)
free(urlbuffer);
if (config.outfile && outs.stream)