cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: jehousley: curl/lib easy.c, 1.103, 1.104 file.c, 1.87, 1.88 ssh.c, 1.57, 1.58 url.c, 1.621, 1.622 urldata.h, 1.333, 1.334

From: James Housley <jim_at_thehousleys.net>
Date: Wed, 27 Jun 2007 16:18:23 -0400

On Jun 27, 2007, at 4:15 PM, cvs_at_labb.contactor.se wrote:

> Index: file.c
> ===================================================================
> RCS file: /cvsroot/curl/curl/lib/file.c,v
> retrieving revision 1.87
> retrieving revision 1.88
> diff -u -d -r1.87 -r1.88
> --- file.c 7 Jun 2007 22:24:53 -0000 1.87
> +++ file.c 27 Jun 2007 20:15:48 -0000 1.88
> @@ -217,8 +217,23 @@
>
> if(data->reqdata.resume_from)
> fp = fopen( file->path, "ab" );
> - else
> + else {
> + int fd;
> +
> +#if defined(WIN32) || defined(MSDOS) || defined(__EMX__)
> + fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,
> + conn->data->set.new_file_perms);
> +#else /* !(WIN32 || MSDOS || __EMX__) */
> + fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC,
> + conn->data->set.new_file_perms);
> +#endif /* !(WIN32 || MSDOS || __EMX__) */
> + if (fd < 0) {
> + failf(data, "Can't open %s for writing", file->path);
> + return CURLE_WRITE_ERROR;
> + }
> + close(fd);
> fp = fopen(file->path, "wb");
> + }
>
> if(!fp) {
> failf(data, "Can't open %s for writing", file->path);

I would have loved to use fdopen() instead of close() then fopen()
but the memory testing complained the file wasn't opened with fopen
(), but really it was. I also wasn't too sure about portability, the
man page seems to say it is fairly standard.

Jim

--
/"\   ASCII Ribbon Campaign  .
\ / - NO HTML/RTF in e-mail  .
  X  - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------
                      http://www.FreeBSD.org     The Power to Serve
jim@TheHousleys.Net  http://www.TheHousleys.net
---------------------------------------------------------------------
The wise man built his network upon Un*x.
     The foolish man built his network upon Windows.
Received on 2007-06-27