diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-09-07 11:56:40 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-09-07 11:56:40 (GMT) |
commit | b8d2426e1bcc860c2c743e2baebbd9c57f117bb9 (patch) | |
tree | 520a1e17f7959578351e35bb808822eed18e8d7e | |
parent | 6269e32c3bc28d6bca8d70ec499e152648356f5c (diff) | |
download | tcl-b8d2426e1bcc860c2c743e2baebbd9c57f117bb9.zip tcl-b8d2426e1bcc860c2c743e2baebbd9c57f117bb9.tar.gz tcl-b8d2426e1bcc860c2c743e2baebbd9c57f117bb9.tar.bz2 |
Use GetFileSizeEx() in stead of GetFileSize(), to get the file size on Windows.
Minor improvement: attach empty .zip file to tclsh.exe (both for Windows and UNIX), zo "zip -A" can be used to modify its zip contents.
-rw-r--r-- | .fossil-settings/binary-glob | 1 | ||||
-rw-r--r-- | generic/tclZipfs.c | 29 | ||||
-rw-r--r-- | tools/empty.zip | bin | 0 -> 22 bytes | |||
-rw-r--r-- | unix/Makefile.in | 1 | ||||
-rw-r--r-- | win/Makefile.in | 1 |
5 files changed, 18 insertions, 14 deletions
diff --git a/.fossil-settings/binary-glob b/.fossil-settings/binary-glob index ec574be..5eebf07 100644 --- a/.fossil-settings/binary-glob +++ b/.fossil-settings/binary-glob @@ -4,6 +4,7 @@ compat/zlib/win64/zdll.lib compat/zlib/win64/zlib1.dll compat/zlib/win64/libz.dll.a compat/zlib/zlib.3.pdf +tools/empty.zip *.bmp *.gif *.png
\ No newline at end of file diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index 0ab60e7..4d716df 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -172,9 +172,9 @@ typedef struct ZipFile { char is_membuf; /* When true, not a file but a memory buffer */ Tcl_Channel chan; /* Channel handle or NULL */ unsigned char *data; /* Memory mapped or malloc'ed file */ - size_t length; /* Length of memory mapped file */ + Tcl_WideUInt length; /* Length of memory mapped file */ unsigned char *tofree; /* Non-NULL if malloc'ed file */ - size_t nfiles; /* Number of files in archive */ + size_t nfiles; /* Number of files in archive */ size_t baseoffs; /* Archive start */ size_t baseoffsp; /* Password start */ size_t centoffs; /* Archive directory start */ @@ -1039,7 +1039,7 @@ ZipFSOpenArchive(Tcl_Interp *interp, const char *zipname, int needZip, ZipFile * goto error; } zf->length = Tcl_Seek(zf->chan, 0, SEEK_END); - if ((zf->length <= 0) || (zf->length > 64 * 1024 * 1024)) { + if ((zf->length < ZIP_CENTRAL_END_LEN) || (zf->length > 64 * 1024 * 1024)) { ZIPFS_ERROR(interp,"illegal file size"); goto error; } @@ -1058,9 +1058,9 @@ ZipFSOpenArchive(Tcl_Interp *interp, const char *zipname, int needZip, ZipFile * zf->chan = NULL; } else { #if defined(_WIN32) || defined(_WIN64) - zf->length = GetFileSize((HANDLE) handle, 0); + i = GetFileSizeEx((HANDLE) handle, (PLARGE_INTEGER)&zf->length); if ( - (zf->length == (size_t)INVALID_FILE_SIZE) || + (i == 0) || (zf->length < ZIP_CENTRAL_END_LEN) ) { ZIPFS_ERROR(interp,"invalid file size"); @@ -1078,15 +1078,15 @@ ZipFSOpenArchive(Tcl_Interp *interp, const char *zipname, int needZip, ZipFile * goto error; } #else - zf->length = lseek((int) (long) handle, 0, SEEK_END); + zf->length = lseek(PTR2INT(handle), 0, SEEK_END); if ((zf->length == (size_t)-1) || (zf->length < ZIP_CENTRAL_END_LEN)) { ZIPFS_ERROR(interp,"invalid file size"); goto error; } - lseek((int) (long) handle, 0, SEEK_SET); + lseek(PTR2INT(handle), 0, SEEK_SET); zf->data = (unsigned char *) mmap(0, zf->length, PROT_READ, MAP_FILE | MAP_PRIVATE, - (int) (long) handle, 0); + PTR2INT(handle), 0); if (zf->data == MAP_FAILED) { ZIPFS_ERROR(interp,"file mapping failed"); goto error; @@ -2103,7 +2103,7 @@ wrerr: * Compressed file larger than input, * write it again uncompressed. */ - if ((int) Tcl_Seek(in, 0, SEEK_SET) != 0) { + if (Tcl_Seek(in, 0, SEEK_SET) != 0) { goto seekErr; } if ((int) Tcl_Seek(out, pos[2], SEEK_SET) != pos[2]) { @@ -4311,14 +4311,15 @@ TclZipfs_Init(Tcl_Interp *interp) Unlock(); if(interp != NULL) { static const EnsembleImplMap initMap[] = { - {"mount", ZipFSMountObjCmd, NULL, NULL, NULL, 0}, - {"mount_data", ZipFSMountBufferObjCmd, NULL, NULL, NULL, 0}, - {"unmount", ZipFSUnmountObjCmd, NULL, NULL, NULL, 0}, - {"mkkey", ZipFSMkKeyObjCmd, NULL, NULL, NULL, 0}, {"mkimg", ZipFSMkImgObjCmd, NULL, NULL, NULL, 0}, {"mkzip", ZipFSMkZipObjCmd, NULL, NULL, NULL, 0}, {"lmkimg", ZipFSLMkImgObjCmd, NULL, NULL, NULL, 0}, {"lmkzip", ZipFSLMkZipObjCmd, NULL, NULL, NULL, 0}, + /* The 4 entries above are not available in safe interpreters */ + {"mount", ZipFSMountObjCmd, NULL, NULL, NULL, 0}, + {"mount_data", ZipFSMountBufferObjCmd, NULL, NULL, NULL, 0}, + {"unmount", ZipFSUnmountObjCmd, NULL, NULL, NULL, 0}, + {"mkkey", ZipFSMkKeyObjCmd, NULL, NULL, NULL, 0}, {"exists", ZipFSExistsObjCmd, NULL, NULL, NULL, 1}, {"info", ZipFSInfoObjCmd, NULL, NULL, NULL, 1}, {"list", ZipFSListObjCmd, NULL, NULL, NULL, 1}, @@ -4349,7 +4350,7 @@ TclZipfs_Init(Tcl_Interp *interp) "}\n"; Tcl_EvalEx(interp, findproc, -1, TCL_EVAL_GLOBAL); Tcl_LinkVar(interp, "::tcl::zipfs::wrmax", (char *) &ZipFS.wrmax,TCL_LINK_INT); - TclMakeEnsemble(interp, "zipfs", initMap); + TclMakeEnsemble(interp, "zipfs", Tcl_IsSafe(interp) ? (initMap+4) : initMap); Tcl_PkgProvide(interp, "zipfs", "2.0"); } return TCL_OK; diff --git a/tools/empty.zip b/tools/empty.zip Binary files differnew file mode 100644 index 0000000..15cb0ec --- /dev/null +++ b/tools/empty.zip diff --git a/unix/Makefile.in b/unix/Makefile.in index 5569b44..2c005b6 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -711,6 +711,7 @@ ${TCL_EXE}: ${TCLSH_OBJS} ${TCL_LIB_FILE} ${TCL_STUB_LIB_FILE} ${CC} ${CFLAGS} ${LDFLAGS} ${TCLSH_OBJS} \ @TCL_BUILD_LIB_SPEC@ ${TCL_STUB_LIB_FILE} ${LIBS} @EXTRA_TCLSH_LIBS@ \ ${CC_SEARCH_FLAGS} -o ${TCL_EXE} + cat ${TOOL_DIR}/empty.zip >> ${TCL_EXE} # Must be empty so it doesn't conflict with rule for ${TCL_EXE} above ${NATIVE_TCLSH}: diff --git a/win/Makefile.in b/win/Makefile.in index a7be485..1d9c522 100644 --- a/win/Makefile.in +++ b/win/Makefile.in @@ -492,6 +492,7 @@ $(TCLSH): $(TCLSH_OBJS) @LIBRARIES@ $(TCL_STUB_LIB_FILE) tclsh.$(RES) $(CC) $(CFLAGS) $(TCLSH_OBJS) $(TCL_LIB_FILE) $(TCL_STUB_LIB_FILE) $(LIBS) \ tclsh.$(RES) $(CC_EXENAME) $(LDFLAGS_CONSOLE) @VC_MANIFEST_EMBED_EXE@ + cat ${TOOL_DIR}/empty.zip >> ${TCLSH} cat32.$(OBJEXT): cat.c $(CC) -c $(CC_SWITCHES) @DEPARG@ $(CC_OBJNAME) |