cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: download an file on Mac OS X

From: Nick Zitzmann <nick_at_chronosnet.com>
Date: Mon, 11 Feb 2013 12:51:13 -0700

On Feb 11, 2013, at 9:26 AM, Jürgen Keser <jkeser_at_computerworks.de> wrote:

> Hi All,
>
> we use Mac OS X 10.8 and Xcode 4.5.2. Here we try now to create our first simple (Cocoa Application) example with the
> curl-library. We will download an file with this library and place the downloaded file to a special place. Enclosed I'll send you
> the code we use until now. The curl_easy_setopt functions return all true, but the file will not be downloaded.
> Also the Cocoa Application will cause an crash at the end. Is there anyone out there who can help me?

I noticed three problems immediately:

> fp = fopen(outfilename,"curl-7.29.0.tar.gz");

This is an illegal use of the fopen() function. Read the man page for more details, but you need to do something like this instead:
fp = fopen("/Path/To/Some/Place/Writable/curl-7.29.0.tar.gz", "w");

> if(CURLE_OK == (res = curl_easy_setopt(curl, CURLOPT_URL, url))){
> NSAlert *alert = [[[NSAlert alloc] init] autorelease];

The NSAlert class is part of the AppKit framework. If you want to use AppKit, you need to initialize it first by calling either NSApplicationMain() or NSApplicationLoad(). See Apple's documentation for more information.

Also, you are autoreleasing an object without first creating an autorelease pool. Unless your tool is using GC (which is deprecated), you must first create an NSAutoreleasePool or use the @autoreleasepool directive before calling -autorelease.

> This message is intended for the addressee only. It contains private and confidential information. The contents are not to be disclosed to anyone other than the addressee. Unauthorized recipients are requested to comply with the above and to inform the sender immediately of any errors in transmission by replying to this message and please delete it from your computer.

I sure hope I'm an authorized recipient… :)

Nick Zitzmann
<http://www.chronosnet.com/>

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-02-11