From cac60f04fca58ee06fd50a449b658cf8d6dde44f Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 31 Jan 2020 07:54:59 +0000 Subject: Add 64-bit seek to the ZipChannel --- generic/tclLink.c | 2 +- generic/tclZipfs.c | 36 ++++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/generic/tclLink.c b/generic/tclLink.c index ecb7aa5..35f1cee 100644 --- a/generic/tclLink.c +++ b/generic/tclLink.c @@ -164,7 +164,7 @@ Tcl_LinkVar( int code; linkPtr = (Link *) Tcl_VarTraceInfo2(interp, varName, NULL, - TCL_GLOBAL_ONLY, LinkTraceProc, (ClientData) NULL); + TCL_GLOBAL_ONLY, LinkTraceProc, NULL); if (linkPtr != NULL) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "variable '%s' is already linked", varName)); diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index 9aa26d9..0b741b7 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -392,6 +392,8 @@ static int ZipChannelRead(void *instanceData, char *buf, int toRead, int *errloc); static int ZipChannelSeek(void *instanceData, long offset, int mode, int *errloc); +static Tcl_WideInt ZipChannelWideSeek(void *instanceData, Tcl_WideInt offset, + int mode, int *errloc); static void ZipChannelWatchChannel(void *instanceData, int mask); static int ZipChannelWrite(void *instanceData, @@ -454,7 +456,7 @@ static Tcl_ChannelType ZipChannelType = { NULL, /* Set blocking mode for raw channel, NULL'able */ NULL, /* Function to flush channel, NULL'able */ NULL, /* Function to handle event, NULL'able */ - NULL, /* Wide seek function, NULL'able */ + ZipChannelWideSeek, /* Wide seek function, NULL'able */ NULL, /* Thread action function, NULL'able */ NULL, /* Truncate function, NULL'able */ }; @@ -1286,7 +1288,7 @@ ZipFSCatalogFilesystem( *zf = *zf0; zf->mountPoint = Tcl_GetHashKey(&ZipFS.zipHash, hPtr); - Tcl_CreateExitHandler(ZipfsExitHandler, (ClientData)zf); + Tcl_CreateExitHandler(ZipfsExitHandler, zf); zf->mountPointLen = strlen(zf->mountPoint); zf->nameLength = strlen(zipname); zf->name = ckalloc(zf->nameLength + 1); @@ -1852,7 +1854,7 @@ TclZipfs_Unmount( ckfree(z); } ZipFSCloseArchive(interp, zf); - Tcl_DeleteExitHandler(ZipfsExitHandler, (ClientData)zf); + Tcl_DeleteExitHandler(ZipfsExitHandler, zf); ckfree(zf); unmounted = 1; done: @@ -3472,7 +3474,7 @@ ZipChannelWrite( /* *------------------------------------------------------------------------- * - * ZipChannelSeek -- + * ZipChannelSeek/ZipChannelWideSeek -- * * This function is called to position file pointer of channel. * @@ -3485,15 +3487,15 @@ ZipChannelWrite( *------------------------------------------------------------------------- */ -static int -ZipChannelSeek( +static Tcl_WideInt +ZipChannelWideSeek( void *instanceData, - long offset, + Tcl_WideInt offset, int mode, int *errloc) { ZipChannel *info = (ZipChannel *) instanceData; - unsigned long end; + size_t end; if (!info->isWriting && (info->isDirectory < 0)) { /* @@ -3525,20 +3527,30 @@ ZipChannelSeek( return -1; } if (info->isWriting) { - if ((unsigned long) offset > info->maxWrite) { + if ((size_t) offset > info->maxWrite) { *errloc = EINVAL; return -1; } - if ((unsigned long) offset > info->numBytes) { + if ((size_t) offset > info->numBytes) { info->numBytes = offset; } - } else if ((unsigned long) offset > end) { + } else if ((size_t) offset > end) { *errloc = EINVAL; return -1; } - info->numRead = (unsigned long) offset; + info->numRead = (size_t) offset; return info->numRead; } + +static int +ZipChannelSeek( + void *instanceData, + long offset, + int mode, + int *errloc) +{ + return ZipChannelWideSeek(instanceData, offset, mode, errloc); +} /* *------------------------------------------------------------------------- -- cgit v0.12