summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2000-03-02 23:06:34 +0000
committerDaniel Stenberg <daniel@haxx.se>2000-03-02 23:06:34 +0000
commitb0936b800719f915ff2a59af61ecbcc08f7bcfd8 (patch)
tree342fe2bdb71e57449693d6859c120f20081a582c
parent8ddd89a323a7599a9ea9ac102df552f8f4488946 (diff)
downloadgnurl-b0936b800719f915ff2a59af61ecbcc08f7bcfd8.tar.gz
gnurl-b0936b800719f915ff2a59af61ecbcc08f7bcfd8.tar.bz2
gnurl-b0936b800719f915ff2a59af61ecbcc08f7bcfd8.zip
Added -N, added a strdup() function for systems without it. suggested for
Ultrix by Damien Adant <dams@usa.net>.
-rw-r--r--src/main.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index 5814efeb2..ca1f4e2d3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -67,6 +67,25 @@
#include <unistd.h>
#endif
+#ifndef HAVE_STRDUP
+/* Ultrix doesn't have strdup(), so make a quick clone: */
+char *strdup(char *str)
+{
+ int len;
+ char *newstr;
+
+ len = strlen(str);
+ newstr = (char *) malloc((len+1)*sizeof(char));
+ if (!newstr)
+ return (char *)NULL;
+
+ strcpy(newstr,str);
+
+ return newstr;
+
+}
+#endif
+
extern void hugehelp(void);
static void helpf(char *fmt, ...)
@@ -109,6 +128,7 @@ static void help(void)
" -m/--max-time <seconds> Maximum time allowed for the transfer\n"
" -M/--manual Display huge help text\n"
" -n/--netrc Read .netrc for user name and password\n"
+ " -N/--no-buffer Disables the buffering of the output stream\n"
" -o/--output <file> Write output to <file> instead of stdout\n"
" -O/--remote-name Write output to a file named as the remote file\n"
#if 0
@@ -177,6 +197,7 @@ struct Configurable {
char *cookiefile;
char *customrequest;
bool progressmode;
+ bool nobuffer;
char *writeout; /* %-styled format string to output */
@@ -288,6 +309,7 @@ static int getparameter(char *flag, /* f or -long-flag */
{"m", "max-time", TRUE},
{"M", "manual", FALSE},
{"n", "netrc", FALSE},
+ {"N", "no-buffer", FALSE},
{"o", "output", TRUE},
{"O", "remote-name", FALSE},
#if 0
@@ -573,6 +595,10 @@ static int getparameter(char *flag, /* f or -long-flag */
automatically enfore user+password with the request */
config->conf ^= CONF_NETRC;
break;
+ case 'N':
+ /* disable the output I/O buffering */
+ config->nobuffer ^= 1;
+ break;
case 'o':
/* output file */
GetStr(&config->outfile, nextarg); /* write to this file */
@@ -806,6 +832,9 @@ struct OutStruct {
FILE *stream;
};
+/* having this global is a bit dirty, but hey, who said we weren't? ;-) */
+struct Configurable config;
+
int my_fwrite(void *buffer, size_t size, size_t nmemb, FILE *stream)
{
struct OutStruct *out=(struct OutStruct *)stream;
@@ -814,6 +843,12 @@ int my_fwrite(void *buffer, size_t size, size_t nmemb, FILE *stream)
out->stream=fopen(out->filename, "wb");
if(!out->stream)
return -1; /* failure */
+ if(config.nobuffer) {
+ /* disable output buffering */
+#ifdef HAVE_SETVBUF
+ setvbuf(out->stream, NULL, _IONBF, 0);
+#endif
+ }
}
return fwrite(buffer, size, nmemb, out->stream);
}
@@ -841,7 +876,6 @@ int main(int argc, char *argv[])
int res=URG_OK;
int i;
- struct Configurable config;
outs.stream = stdout;