diff options
Diffstat (limited to 'lib/file.c')
-rw-r--r-- | lib/file.c | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/lib/file.c b/lib/file.c index 4f3ea1bb4..00d5fc09b 100644 --- a/lib/file.c +++ b/lib/file.c @@ -23,27 +23,13 @@ #include "setup.h" #ifndef CURL_DISABLE_FILE -/* -- WIN32 approved -- */ -#include <stdio.h> -#include <string.h> -#include <stdarg.h> -#include <stdlib.h> -#include <ctype.h> - -#ifdef WIN32 -#include <time.h> -#include <io.h> -#include <fcntl.h> -#else + #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif #ifdef HAVE_NETINET_IN_H #include <netinet/in.h> #endif -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#endif #ifdef HAVE_UNISTD_H #include <unistd.h> #endif @@ -68,8 +54,6 @@ #include <fcntl.h> #endif -#endif /* WIN32 */ - #include "strtoofft.h" #include "urldata.h" #include <curl/curl.h> @@ -83,6 +67,7 @@ #include "url.h" #include "curl_memory.h" #include "parsedate.h" /* for the week day and month names */ +#include "warnless.h" #define _MPRINTF_REPLACE /* use our functions only */ #include <curl/mprintf.h> @@ -109,6 +94,9 @@ static CURLcode file_do(struct connectdata *, bool *done); static CURLcode file_done(struct connectdata *conn, CURLcode status, bool premature); static CURLcode file_connect(struct connectdata *conn, bool *done); +static CURLcode file_disconnect(struct connectdata *conn, + bool dead_connection); + /* * FILE scheme handler. @@ -125,8 +113,9 @@ const struct Curl_handler Curl_handler_file = { ZERO_NULL, /* doing */ ZERO_NULL, /* proto_getsock */ ZERO_NULL, /* doing_getsock */ + ZERO_NULL, /* domore_getsock */ ZERO_NULL, /* perform_getsock */ - ZERO_NULL, /* disconnect */ + file_disconnect, /* disconnect */ ZERO_NULL, /* readwrite */ 0, /* defport */ CURLPROTO_FILE, /* protocol */ @@ -222,10 +211,9 @@ static CURLcode file_connect(struct connectdata *conn, bool *done) /* file is not a protocol that can deal with "persistancy" */ file = data->state.proto.file; Curl_safefree(file->freepath); + file->path = NULL; if(file->fd != -1) close(file->fd); - file->path = NULL; - file->freepath = NULL; file->fd = -1; } @@ -282,10 +270,31 @@ static CURLcode file_done(struct connectdata *conn, struct FILEPROTO *file = conn->data->state.proto.file; (void)status; /* not used */ (void)premature; /* not used */ - Curl_safefree(file->freepath); - if(file->fd != -1) - close(file->fd); + if(file) { + Curl_safefree(file->freepath); + file->path = NULL; + if(file->fd != -1) + close(file->fd); + file->fd = -1; + } + + return CURLE_OK; +} + +static CURLcode file_disconnect(struct connectdata *conn, + bool dead_connection) +{ + struct FILEPROTO *file = conn->data->state.proto.file; + (void)dead_connection; /* not used */ + + if(file) { + Curl_safefree(file->freepath); + file->path = NULL; + if(file->fd != -1) + close(file->fd); + file->fd = -1; + } return CURLE_OK; } @@ -438,7 +447,6 @@ static CURLcode file_do(struct connectdata *conn, bool *done) curl_off_t expected_size=0; bool fstated=FALSE; ssize_t nread; - size_t bytestoread; struct SessionHandle *data = conn->data; char *buf = data->state.buffer; curl_off_t bytecount = 0; @@ -560,7 +568,10 @@ static CURLcode file_do(struct connectdata *conn, bool *done) while(res == CURLE_OK) { /* Don't fill a whole buffer if we want less than all data */ - bytestoread = (expected_size < BUFSIZE-1)?(size_t)expected_size:BUFSIZE-1; + size_t bytestoread = + (expected_size < CURL_OFF_T_C(BUFSIZE) - CURL_OFF_T_C(1)) ? + curlx_sotouz(expected_size) : BUFSIZE - 1; + nread = read(fd, buf, bytestoread); if(nread > 0) |