MESSAGE
DATE | 2004-11-24 |
FROM | Ruben Safir Secretary NYLXS
|
SUBJECT | Re: [hangout] C/C++ coding problem.
|
From owner-hangouts-destenys-at-mrbrklyn.com Wed Nov 24 06:40:20 2004 X-UIDL: Aj)#!PG3"!`PL!!W:R"! Received: from www2.mrbrklyn.com (localhost [127.0.0.1]) by mrbrklyn.com (8.12.11/8.11.2/SuSE Linux 8.11.1-0.5) with ESMTP id iAOBeKgO029201 for ; Wed, 24 Nov 2004 06:40:20 -0500 Received: (from mdom-at-localhost) by www2.mrbrklyn.com (8.12.11/8.12.3/Submit) id iAOBeJd2029200 for hangouts-destenys; Wed, 24 Nov 2004 06:40:19 -0500 X-Authentication-Warning: www2.mrbrklyn.com: mdom set sender to owner-hangouts-at-www2.mrbrklyn.com using -f Received: from www2.mrbrklyn.com (localhost [127.0.0.1]) by mrbrklyn.com (8.12.11/8.11.2/SuSE Linux 8.11.1-0.5) with ESMTP id iAOBeJSK029194; Wed, 24 Nov 2004 06:40:19 -0500 Received: (from ruben-at-localhost) by www2.mrbrklyn.com (8.12.11/8.12.3/Submit) id iAOBeI9V029193; Wed, 24 Nov 2004 06:40:18 -0500 Date: Wed, 24 Nov 2004 06:40:18 -0500 From: Ruben Safir Secretary NYLXS To: Billy Cc: swd , hangout-at-nylxs.com Subject: Re: [hangout] C/C++ coding problem. Message-ID: <20041124114018.GC29078-at-www2.mrbrklyn.com> References: <200411230202.17826.sderrick-at-optonline.net> <20041123080651.GA32587-at-www2.mrbrklyn.com> <20041124102409.GA16323-at-mail.dadadada.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20041124102409.GA16323-at-mail.dadadada.net> User-Agent: Mutt/1.3.27i Sender: owner-hangouts-at-mrbrklyn.com Precedence: bulk Reply-To: Ruben Safir Secretary NYLXS List: New Yorker GNU Linux Scene Admin: To unsubscribe send unsubscribe name-at-domian.com in the body to hangout-request-at-www2.mrbrklyn.com X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on www2.mrbrklyn.com X-Spam-Status: No, score=-5.9 required=4.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.0.0 X-Spam-Level: X-Keywords: X-UID: 39118 Status: RO Content-Length: 2843 Lines: 110
> > 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
|
|