~ubuntu-branches/ubuntu/vivid/curl/vivid

« back to all changes in this revision

Viewing changes to lib/file.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Schuldei
  • Date: 2009-04-02 23:35:45 UTC
  • mto: (1.2.1 upstream) (3.2.3 sid)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20090402233545-geixkwhe3izccjt7
Tags: upstream-7.19.4
ImportĀ upstreamĀ versionĀ 7.19.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
 
8
 * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
9
9
 *
10
10
 * This software is licensed as described in the file COPYING, which
11
11
 * you should have received as part of this distribution. The terms
18
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
 * KIND, either express or implied.
20
20
 *
21
 
 * $Id: file.c,v 1.109 2008-05-21 21:36:42 danf Exp $
 
21
 * $Id: file.c,v 1.119 2009-02-03 22:28:41 bagder Exp $
22
22
 ***************************************************************************/
23
23
 
24
24
#include "setup.h"
57
57
#ifdef HAVE_NET_IF_H
58
58
#include <net/if.h>
59
59
#endif
 
60
#ifdef HAVE_SYS_IOCTL_H
60
61
#include <sys/ioctl.h>
61
 
#include <signal.h>
 
62
#endif
62
63
 
63
64
#ifdef HAVE_SYS_PARAM_H
64
65
#include <sys/param.h>
118
119
  ZERO_NULL,                            /* doing */
119
120
  ZERO_NULL,                            /* proto_getsock */
120
121
  ZERO_NULL,                            /* doing_getsock */
 
122
  ZERO_NULL,                            /* perform_getsock */
121
123
  ZERO_NULL,                            /* disconnect */
122
124
  0,                                    /* defport */
123
125
  PROT_FILE                             /* protocol */
202
204
  Curl_reset_reqproto(conn);
203
205
 
204
206
  if(!data->state.proto.file) {
205
 
    file = (struct FILEPROTO *)calloc(sizeof(struct FILEPROTO), 1);
 
207
    file = calloc(sizeof(struct FILEPROTO), 1);
206
208
    if(!file) {
207
209
      free(real_path);
208
210
      return CURLE_OUT_OF_MEMORY;
333
335
      failf(data, "Can't open %s for writing", file->path);
334
336
      return CURLE_WRITE_ERROR;
335
337
    }
336
 
    fp = fdopen(fd, "wb");
 
338
    close(fd);
 
339
    fp = fopen(file->path, "wb");
337
340
  }
338
341
 
339
342
  if(!fp) {
347
350
 
348
351
  /* treat the negative resume offset value as the case of "-" */
349
352
  if(data->state.resume_from < 0) {
350
 
    if(stat(file->path, &file_stat)) {
 
353
    if(fstat(fileno(fp), &file_stat)) {
351
354
      fclose(fp);
352
355
      failf(data, "Can't get the size of %s", file->path);
353
356
      return CURLE_WRITE_ERROR;
451
454
  if( -1 != fstat(fd, &statbuf)) {
452
455
    /* we could stat it, then read out the size */
453
456
    expected_size = statbuf.st_size;
 
457
    /* and store the modification time */
 
458
    data->info.filetime = (long)statbuf.st_mtime;
454
459
    fstated = TRUE;
455
460
  }
456
461
 
491
496
               tm->tm_sec);
492
497
      result = Curl_client_write(conn, CLIENTWRITE_BOTH, buf, 0);
493
498
    }
 
499
    /* if we fstat()ed the file, set the file size to make it available post-
 
500
       transfer */
 
501
    if(fstated)
 
502
      Curl_pgrsSetDownloadSize(data, expected_size);
494
503
    return result;
495
504
  }
496
505