Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "tool_setup.h"
00023
00024 #define ENABLE_CURLX_PRINTF
00025
00026 #include "curlx.h"
00027
00028 #include "tool_cfgable.h"
00029 #include "tool_cb_see.h"
00030
00031 #include "memdebug.h"
00032
00033
00034
00035
00036
00037 #define OUR_MAX_SEEK_L 2147483647L - 1L
00038 #define OUR_MAX_SEEK_O CURL_OFF_T_C(0x7FFFFFFF) - CURL_OFF_T_C(0x1)
00039
00040
00041
00042
00043
00044
00045
00046
00047 int tool_seek_cb(void *userdata, curl_off_t offset, int whence)
00048 {
00049 struct InStruct *in = userdata;
00050
00051 #if(CURL_SIZEOF_CURL_OFF_T > SIZEOF_OFF_T) && !defined(USE_WIN32_LARGE_FILES)
00052
00053
00054
00055
00056
00057 if(offset > OUR_MAX_SEEK_O) {
00058
00059
00060
00061 curl_off_t left = offset;
00062
00063 if(whence != SEEK_SET)
00064
00065 return CURL_SEEKFUNC_FAIL;
00066
00067 if(LSEEK_ERROR == lseek(in->fd, 0, SEEK_SET))
00068
00069 return CURL_SEEKFUNC_FAIL;
00070
00071 while(left) {
00072 long step = (left > OUR_MAX_SEEK_O) ? OUR_MAX_SEEK_L : (long)left;
00073 if(LSEEK_ERROR == lseek(in->fd, step, SEEK_CUR))
00074
00075 return CURL_SEEKFUNC_FAIL;
00076 left -= step;
00077 }
00078 return CURL_SEEKFUNC_OK;
00079 }
00080 #endif
00081
00082 if(LSEEK_ERROR == lseek(in->fd, offset, whence))
00083
00084
00085
00086 return CURL_SEEKFUNC_CANTSEEK;
00087
00088 return CURL_SEEKFUNC_OK;
00089 }
00090
00091 #if defined(WIN32) && !defined(__MINGW64__)
00092
00093 #ifdef __BORLANDC__
00094
00095 # define _lseeki64(hnd,ofs,whence) lseek(hnd,ofs,whence)
00096 #endif
00097
00098 #ifdef __POCC__
00099 # if(__POCC__ < 450)
00100
00101 # define _lseeki64(hnd,ofs,whence) _lseek(hnd,ofs,whence)
00102 # else
00103 # define _lseeki64(hnd,ofs,whence) _lseek64(hnd,ofs,whence)
00104 # endif
00105 #endif
00106
00107 #ifdef _WIN32_WCE
00108
00109 # undef _lseeki64
00110 # define _lseeki64(hnd,ofs,whence) lseek(hnd,ofs,whence)
00111 # undef _get_osfhandle
00112 # define _get_osfhandle(fd) (fd)
00113 #endif
00114
00115
00116
00117
00118
00119 int tool_ftruncate64(int fd, curl_off_t where)
00120 {
00121 if(_lseeki64(fd, where, SEEK_SET) < 0)
00122 return -1;
00123
00124 if(!SetEndOfFile((HANDLE)_get_osfhandle(fd)))
00125 return -1;
00126
00127 return 0;
00128 }
00129
00130 #endif
00131