MESSAGE
DATE | 2004-11-24 |
FROM | Ruben Safir Secretary NYLXS
|
SUBJECT | Re: [hangout] C/C++ coding problem.
|
> > Sheesh! Do you think Perl is the only language with libraries? >
No. There is Python and Java.
> > You have forced my hand, sir.. I present a poor-man's lwp-request, > which compiles down to a 6k executable on my Debian system. > > Most of the code is error checking.. if you didn't care about > that, you could probably do this in 10 lines and just dump > the URL to stdout. > > ===== curlbilly.c ===== > > #include > > int > download(char *url, FILE*fp) > { > CURLcode res; > CURL *curl; > char curlerrbuf[CURL_ERROR_SIZE]; > curl = curl_easy_init(); > curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curlerrbuf); > curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); > curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); > curl_easy_setopt(curl, CURLOPT_URL, url); > curl_easy_setopt(curl, CURLOPT_FILE, fp); > if(!curl){ > fprintf(stderr, "curl initialization error\n"); > return -1; > } > res = curl_easy_perform(curl); > if(res){ > fprintf(stderr, "download failure:\n%s\n", curlerrbuf); > } > curl_easy_cleanup(curl); > return res; > } > > > int > main(int argc, char **argv) > { > char *url; > char *ofn; > FILE *ofile; > if(argc!=3){ > fprintf(stderr, "Usage:\n\n\t%s url outfile\n\n", argv[0]); > exit(1); > } > curl_global_init(CURL_GLOBAL_ALL); > url = argv[1]; > ofn = argv[2]; > if(!(ofile = fopen(ofn, "w"))){ > fprintf(stderr, "Error: couldn't open '%s' for writing:\n", ofn); > perror(""); > exit(1); > } > fprintf(stderr, "getting url: '%s' as file '%s'\n", url, ofn); > download(url, ofile); > fclose(ofile); > curl_global_cleanup(); > return 0; > } > > ===== Makefile ===== > > CC=`curl-config --cc` > CFLAGS=`curl-config --cflags` > LDFLAGS=`curl-config --libs` > > TESTURL="http://www.nylxs.com" > > all: curlbilly > > test: nylxs-index.html > > nylxs-index.html: curlbilly > ./curlbilly $(TESTURL) nylxs-index.html
Cool
-- __________________________ Brooklyn Linux Solutions
So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 http://fairuse.nylxs.com
http://www.mrbrklyn.com - Consulting http://www.inns.net <-- Happy Clients http://www.nylxs.com - Leadership Development in Free Software http://www2.mrbrklyn.com/resources - Unpublished Archive or stories and articles from around the net http://www2.mrbrklyn.com/downtown.html - See the New Downtown Brooklyn....
____________________________ NYLXS: New Yorker Free Software Users Scene Fair Use - because it's either fair use or useless.... NYLXS is a trademark of NYLXS, Inc
|
|