~ubuntu-branches/ubuntu/natty/curl/natty-security

« back to all changes in this revision

Viewing changes to tests/libtest/lib541.c

  • Committer: Bazaar Package Importer
  • Author(s): Bhavani Shankar
  • Date: 2010-06-20 13:56:28 UTC
  • mfrom: (3.4.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100620135628-e30tp9jldq6hq985
Tags: 7.21.0-1ubuntu1
* Merge from debian unstable.  Remaining changes: LP: #596334
  - Keep build deps in main:
    - Drop build dependencies: stunnel, libssh2-1-dev
    - Add build-dependency on openssh-server
    - Drop libssh2-1-dev from libcurl4-openssl-dev's Depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * $Id: lib541.c,v 1.4 2008-09-20 04:26:57 yangtse Exp $
9
8
 */
10
9
 
11
 
#include "setup.h" /* struct_stat etc. */
12
10
#include "test.h"
13
11
 
14
12
#ifdef HAVE_SYS_SOCKET_H
48
46
    return -1;
49
47
  }
50
48
 
 
49
  hd_src = fopen(libtest_arg2, "rb");
 
50
  if(NULL == hd_src) {
 
51
    error = ERRNO;
 
52
    fprintf(stderr, "fopen() failed with error: %d %s\n",
 
53
            error, strerror(error));
 
54
    fprintf(stderr, "Error opening file: %s\n", libtest_arg2);
 
55
    return -2; /* if this happens things are major weird */
 
56
  }
 
57
 
51
58
  /* get the file size of the local file */
52
 
  hd = stat(libtest_arg2, &file_info);
 
59
  hd = fstat(fileno(hd_src), &file_info);
53
60
  if(hd == -1) {
54
61
    /* can't open file, bail out */
55
62
    error = ERRNO;
56
 
    fprintf(stderr, "stat() failed with error: %d %s\n",
 
63
    fprintf(stderr, "fstat() failed with error: %d %s\n",
57
64
            error, strerror(error));
58
 
    fprintf(stderr, "WARNING: cannot open file %s\n", libtest_arg2);
 
65
    fprintf(stderr, "ERROR: cannot open file %s\n", libtest_arg2);
 
66
    fclose(hd_src);
59
67
    return -1;
60
68
  }
61
69
 
62
70
  if(! file_info.st_size) {
63
 
    fprintf(stderr, "WARNING: file %s has no size!\n", libtest_arg2);
 
71
    fprintf(stderr, "ERROR: file %s has zero size!\n", libtest_arg2);
 
72
    fclose(hd_src);
64
73
    return -4;
65
74
  }
66
75
 
67
 
  /* get a FILE * of the same file, could also be made with
68
 
     fdopen() from the previous descriptor, but hey this is just
69
 
     an example! */
70
 
  hd_src = fopen(libtest_arg2, "rb");
71
 
  if(NULL == hd_src) {
72
 
    error = ERRNO;
73
 
    fprintf(stderr, "fopen() failed with error: %d %s\n",
74
 
            error, strerror(error));
75
 
    fprintf(stderr, "Error opening file: %s\n", libtest_arg2);
76
 
    return -2; /* if this happens things are major weird */
77
 
  }
78
 
 
79
76
  if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
80
77
    fprintf(stderr, "curl_global_init() failed\n");
81
78
    fclose(hd_src);
91
88
  }
92
89
 
93
90
  /* enable uploading */
94
 
  curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
 
91
  test_setopt(curl, CURLOPT_UPLOAD, 1L);
95
92
 
96
93
  /* enable verbose */
97
 
  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
 
94
  test_setopt(curl, CURLOPT_VERBOSE, 1L);
98
95
 
99
96
  /* specify target */
100
 
  curl_easy_setopt(curl,CURLOPT_URL, URL);
 
97
  test_setopt(curl,CURLOPT_URL, URL);
101
98
 
102
99
  /* now specify which file to upload */
103
 
  curl_easy_setopt(curl, CURLOPT_INFILE, hd_src);
 
100
  test_setopt(curl, CURLOPT_INFILE, hd_src);
104
101
 
105
102
  /* Now run off and do what you've been told! */
106
103
  res = curl_easy_perform(curl);
109
106
     is at end of file */
110
107
  res = curl_easy_perform(curl);
111
108
 
 
109
test_cleanup:
 
110
 
112
111
  /* close the local file */
113
112
  fclose(hd_src);
114
113