cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: >2 GB file support

From: Rob Braun <bbraun_at_synack.net>
Date: Tue, 12 Aug 2003 21:06:52 -0700

Attached is a simple update to the diff that fixes the progress
display totals. The diff is against curl-7.10.7-pre4, BTW.

Rob

On Tue, Aug 12, 2003 at 06:42:16PM -0700, Rob Braun wrote:
> I had a brief conversation today in SourceForge's bug tracking
> system with Daniel Stenberg about curl and >2GB file support
> in libcurl. I was pointed at this list.
>
> So, I have libcurl downloading >2GB files with the patch I'm
> attaching to this mail. This is a preliminary patch that has
> several caveats:
> 1) I have only tested http/https downloads. I haven't tested ftp,
> although the changes should work for ftp as well.
> 2) This adds a new type "filesize_t", which I've simply #defined
> to int64_t. This should be autoconf'd to something more reasonable.
> 3) This change is binary incompatible with the existing libcurl.
> This changes the size of several libcurl structures, and the parameters
> to several functions.
> 4) One problem with autoconf'ing the type of filesize_t, is that there
> are many printf() and one sscanf() strings that need to be updated
> depending on the size of filesize_t. This could be done with macros
> or internal functions to generate the correct printf()/scanf() strings
> depending on the size of filesize_t. I'm open to suggestions on how
> best to implement that, for portability.
> 4) I haven't done extensive testing, but "works for me" =)
>
> Anyway, I'd love to get comments/flames/suggestions on this patch.
>
> Thanks,
> Rob

> diff -udr curl-7.10.7-pre4/lib/dict.c curl-7.10.7-pre4-bf/lib/dict.c
> --- curl-7.10.7-pre4/lib/dict.c Fri Jul 25 01:30:58 2003
> +++ curl-7.10.7-pre4-bf/lib/dict.c Tue Aug 12 16:20:57 2003
> @@ -92,7 +92,7 @@
> struct SessionHandle *data=conn->data;
>
> char *path = conn->path;
> - long *bytecount = &conn->bytecount;
> + filesize_t *bytecount = &conn->bytecount;
>
> if(conn->bits.user_passwd) {
> /* AUTH is missing */
> diff -udr curl-7.10.7-pre4/lib/ftp.c curl-7.10.7-pre4-bf/lib/ftp.c
> --- curl-7.10.7-pre4/lib/ftp.c Sun Aug 10 10:11:41 2003
> +++ curl-7.10.7-pre4-bf/lib/ftp.c Tue Aug 12 16:20:25 2003
> @@ -1557,7 +1557,7 @@
>
> /* the ftp struct is already inited in Curl_ftp_connect() */
> struct FTP *ftp = conn->proto.ftp;
> - long *bytecountp = ftp->bytecountp;
> + filesize_t *bytecountp = ftp->bytecountp;
>
> if(data->set.upload) {
>
> diff -udr curl-7.10.7-pre4/lib/http.h curl-7.10.7-pre4-bf/lib/http.h
> --- curl-7.10.7-pre4/lib/http.h Mon Aug 11 04:47:45 2003
> +++ curl-7.10.7-pre4-bf/lib/http.h Tue Aug 12 16:17:06 2003
> @@ -41,7 +41,7 @@
> /* The following functions are defined in http_chunks.c */
> void Curl_httpchunk_init(struct connectdata *conn);
> CHUNKcode Curl_httpchunk_read(struct connectdata *conn, char *datap,
> - ssize_t length, ssize_t *wrote);
> + filesize_t length, ssize_t *wrote);
> void Curl_http_auth_stage(struct SessionHandle *data, int stage);
> #endif
> #endif
> diff -udr curl-7.10.7-pre4/lib/transfer.c curl-7.10.7-pre4-bf/lib/transfer.c
> --- curl-7.10.7-pre4/lib/transfer.c Mon Aug 11 04:47:45 2003
> +++ curl-7.10.7-pre4-bf/lib/transfer.c Tue Aug 12 16:24:23 2003
> @@ -579,7 +579,7 @@
>
> /* check for Content-Length: header lines to get size */
> if (checkprefix("Content-Length:", k->p) &&
> - sscanf (k->p+15, " %ld", &k->contentlength)) {
> + sscanf (k->p+15, " %lld", &k->contentlength)) {
> conn->size = k->contentlength;
> Curl_pgrsSetDownloadSize(data, k->contentlength);
> }
> @@ -1308,12 +1308,12 @@
> if(!(data->set.no_body) && k->contentlength &&
> (k->bytecount != k->contentlength) &&
> !conn->newurl) {
> - failf(data, "transfer closed with %d bytes remaining to read",
> + failf(data, "transfer closed with %lld bytes remaining to read",
> k->contentlength-k->bytecount);
> return CURLE_PARTIAL_FILE;
> }
> else if(conn->bits.chunk && conn->proto.http->chunk.datasize) {
> - failf(data, "transfer closed with at least %d bytes remaining",
> + failf(data, "transfer closed with at least %lld bytes remaining",
> conn->proto.http->chunk.datasize);
> return CURLE_PARTIAL_FILE;
> }
> @@ -2024,12 +2024,12 @@
> CURLcode
> Curl_Transfer(struct connectdata *c_conn, /* connection data */
> int sockfd, /* socket to read from or -1 */
> - int size, /* -1 if unknown at this point */
> + filesize_t size, /* -1 if unknown at this point */
> bool getheader, /* TRUE if header parsing is wanted */
> - long *bytecountp, /* return number of bytes read or NULL */
> + filesize_t *bytecountp, /* return number of bytes read or NULL */
> int writesockfd, /* socket to write to, it may very well be
> the same we read from. -1 disables */
> - long *writebytecountp /* return number of bytes written or
> + filesize_t *writebytecountp /* return number of bytes written or
> NULL */
> )
> {
> diff -udr curl-7.10.7-pre4/lib/transfer.h curl-7.10.7-pre4-bf/lib/transfer.h
> --- curl-7.10.7-pre4/lib/transfer.h Thu Jan 16 13:08:13 2003
> +++ curl-7.10.7-pre4-bf/lib/transfer.h Tue Aug 12 16:15:42 2003
> @@ -38,11 +38,11 @@
> CURLcode
> Curl_Transfer (struct connectdata *data,
> int sockfd, /* socket to read from or -1 */
> - int size, /* -1 if unknown at this point */
> + filesize_t size, /* -1 if unknown at this point */
> bool getheader, /* TRUE if header parsing is wanted */
> - long *bytecountp, /* return number of bytes read */
> + filesize_t *bytecountp, /* return number of bytes read */
> int writesockfd, /* socket to write to, it may very well be
> the same we read from. -1 disables */
> - long *writebytecountp /* return number of bytes written */
> + filesize_t *writebytecountp /* return number of bytes written */
> );
> #endif
> diff -udr curl-7.10.7-pre4/lib/urldata.h curl-7.10.7-pre4-bf/lib/urldata.h
> --- curl-7.10.7-pre4/lib/urldata.h Mon Aug 11 16:15:41 2003
> +++ curl-7.10.7-pre4-bf/lib/urldata.h Tue Aug 12 18:32:27 2003
> @@ -27,6 +27,9 @@
>
> #include "setup.h"
>
> +/* XXX Remove me */
> +#define filesize_t int64_t
> +
> #define PORT_FTP 21
> #define PORT_TELNET 23
> #define PORT_GOPHER 70
> @@ -203,8 +206,8 @@
>
> const char *p_pragma; /* Pragma: string */
> const char *p_accept; /* Accept: string */
> - long readbytecount;
> - long writebytecount;
> + filesize_t readbytecount;
> + filesize_t writebytecount;
>
> /* For FORM posting */
> struct Form form;
> @@ -232,7 +235,7 @@
> * FTP unique setup
> ***************************************************************************/
> struct FTP {
> - long *bytecountp;
> + filesize_t *bytecountp;
> char *user; /* user name string */
> char *passwd; /* password string */
> char *urlpath; /* the originally given path part of the URL */
> @@ -296,10 +299,11 @@
> * losing state.
> */
>
> +
> struct Curl_transfer_keeper {
> - int bytecount; /* total number of bytes read */
> - int writebytecount; /* number of bytes written */
> - long contentlength; /* size of incoming data */
> + filesize_t bytecount; /* total number of bytes read */
> + filesize_t writebytecount; /* number of bytes written */
> + filesize_t contentlength; /* size of incoming data */
> struct timeval start; /* transfer started at this time */
> struct timeval now; /* current time */
> bool header; /* incoming data has HTTP header */
> @@ -319,7 +323,7 @@
> char *end_ptr; /* within buf */
> char *p; /* within headerbuff */
> bool content_range; /* set TRUE if Content-Range: was found */
> - int offset; /* possible resume offset read from the
> + filesize_t offset; /* possible resume offset read from the
> Content-Range: header */
> int httpcode; /* error code from the 'HTTP/1.? XXX' line */
> int httpversion; /* the HTTP version*10 */
> @@ -418,12 +422,12 @@
> unsigned short remote_port; /* what remote port to connect to,
> not the proxy port! */
> char *ppath;
> - long bytecount;
> + filesize_t bytecount;
> long headerbytecount; /* only count received headers */
>
> char *range; /* range, if used. See README for detailed specification on
> this syntax. */
> - ssize_t resume_from; /* continue [ftp] transfer from here */
> + filesize_t resume_from; /* continue [ftp] transfer from here */
>
> char *proxyhost; /* name of the http proxy host */
>
> @@ -437,7 +441,7 @@
> struct timeval created; /* creation time */
> int firstsocket; /* the main socket to use */
> int secondarysocket; /* for i.e ftp transfers */
> - long maxdownload; /* in bytes, the maximum amount of data to fetch, 0
> + filesize_t maxdownload; /* in bytes, the maximum amount of data to fetch, 0
> means unlimited */
>
> struct ssl_connect_data ssl; /* this is for ssl-stuff */
> @@ -475,13 +479,13 @@
>
> /* READ stuff */
> int sockfd; /* socket to read from or -1 */
> - int size; /* -1 if unknown at this point */
> - long *bytecountp; /* return number of bytes read or NULL */
> + filesize_t size; /* -1 if unknown at this point */
> + filesize_t *bytecountp; /* return number of bytes read or NULL */
>
> /* WRITE stuff */
> int writesockfd; /* socket to write to, it may very well be
> the same we read from. -1 disables */
> - long *writebytecountp; /* return number of bytes written or NULL */
> + filesize_t *writebytecountp; /* return number of bytes written or NULL */
>
> /** Dynamicly allocated strings, may need to be freed before this **/
> /** struct is killed. **/

-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01

Received on 2003-08-13