diff options
| author | Tomas Bzatek <tbzatek@redhat.com> | 2023-12-17 21:23:58 +0100 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@redhat.com> | 2023-12-17 21:23:58 +0100 |
| commit | 02d6107c97b48888362e7c6a70dcac323c89d741 (patch) | |
| tree | 5069a77adaf73f7249ac79b6c49a47168a647ef8 /zip/ZipArchive/ZipFile_stl.cpp | |
| parent | 4e17c2527b106f1b493a3ac77c89858d14f834e2 (diff) | |
| download | tuxcmd-modules-02d6107c97b48888362e7c6a70dcac323c89d741.tar.xz | |
ZipArchive: Update to the 4.6.9 release
Diffstat (limited to 'zip/ZipArchive/ZipFile_stl.cpp')
| -rw-r--r-- | zip/ZipArchive/ZipFile_stl.cpp | 133 |
1 files changed, 108 insertions, 25 deletions
diff --git a/zip/ZipArchive/ZipFile_stl.cpp b/zip/ZipArchive/ZipFile_stl.cpp index 7bbedd7..9585004 100644 --- a/zip/ZipArchive/ZipFile_stl.cpp +++ b/zip/ZipArchive/ZipFile_stl.cpp @@ -1,6 +1,6 @@ ////////////////////////////////////////////////////////////////////////////////
-// This source file is part of the ZipArchive library source distribution and
-// is Copyrighted 2000 - 2007 by Artpol Software - Tadeusz Dracz
+// This source file is part of the ZipArchive Library Open Source distribution
+// and is Copyrighted 2000 - 2022 by Artpol Software - Tadeusz Dracz
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
@@ -9,12 +9,12 @@ //
// For the licensing details refer to the License.txt file.
//
-// Web Site: http://www.artpol-software.com
+// Web Site: https://www.artpol-software.com
////////////////////////////////////////////////////////////////////////////////
-#include "_features.h"
+#include "stdafx.h"
-#if defined ZIP_ARCHIVE_STL || defined ZIP_FILE_USES_STL
+#if (defined _ZIP_IMPL_STL && (!defined _ZIP_FILE_IMPLEMENTATION || _ZIP_FILE_IMPLEMENTATION == ZIP_ZFI_DEFAULT)) || _ZIP_FILE_IMPLEMENTATION == ZIP_ZFI_STL
#if defined __APPLE__ || defined __CYGWIN__
#define FILE_FUNCTIONS_64B_BY_DEFAULT
@@ -22,13 +22,19 @@ #undef FILE_FUNCTIONS_64B_BY_DEFAULT
#endif
-#include "stdafx.h"
#include "ZipFile.h"
#include "ZipException.h"
#include "ZipPlatform.h"
+#include "BitFlag.h"
#include <fcntl.h>
+CZipFile::CZipFile(LPCTSTR lpszFileName, UINT openFlags)
+{
+ m_hFile = -1;
+ Open(lpszFileName, openFlags, true);
+}
+
CZipFile::CZipFile()
{
m_hFile = -1;
@@ -44,13 +50,25 @@ ZIP_FILE_USIZE CZipFile::GetLength() const {
// cannot use Seek here, Seek is not const
ZIP_SIZE_TYPE lLen, lCur;
- lCur = _lseek(m_hFile, 0, current);
+#ifdef FILE_FUNCTIONS_64B_BY_DEFAULT
+ lCur = (ZIP_SIZE_TYPE)_lseek(m_hFile, 0, current);
+#else
+ lCur = (ZIP_SIZE_TYPE)_lseeki64(m_hFile, 0, current);
+#endif
if (lCur == (ZIP_SIZE_TYPE)-1)
ThrowError();
- lLen = _lseek(m_hFile, 0, end);
+#ifdef FILE_FUNCTIONS_64B_BY_DEFAULT
+ lLen = (ZIP_SIZE_TYPE)_lseek(m_hFile, 0, end);
+#else
+ lLen = (ZIP_SIZE_TYPE)_lseeki64(m_hFile, 0, end);
+#endif
// first go back
+#ifdef FILE_FUNCTIONS_64B_BY_DEFAULT
bool err = _lseek(m_hFile, lCur, begin) == -1;
+#else
+ bool err = _lseeki64(m_hFile, lCur, begin) == -1;
+#endif
if (err || lLen == (ZIP_SIZE_TYPE)-1)
ThrowError();
@@ -71,27 +89,36 @@ bool CZipFile::Open(LPCTSTR lpszFileName, UINT openFlags, bool bThrow) #endif
bool bReadOnly = false;
- if (openFlags & CZipFile::modeCreate)
- iNewFlags |= O_CREAT;
- if ((openFlags & CZipFile::modeReadWrite) == CZipFile::modeReadWrite)
+ DWORD temp = openFlags & 3;
+ if (temp == modeWrite)
+ {
+ iNewFlags |= O_WRONLY;
+ }
+ else if (temp == modeReadWrite)
+ {
iNewFlags |= O_RDWR;
- else if (openFlags & CZipFile::modeRead)
+ }
+ else
{
// O_RDONLY is defined as 0
bReadOnly = true;
iNewFlags |= O_RDONLY;
}
- else if (openFlags & CZipFile::modeWrite)
- iNewFlags |= O_WRONLY;
+
+ if (openFlags & modeCreate)
+ iNewFlags |= O_CREAT;
- if (!(openFlags & CZipFile::modeNoTruncate) && !bReadOnly)
+ if (!(openFlags & modeNoTruncate) && !bReadOnly)
iNewFlags |= O_TRUNC;
- m_hFile = ZipPlatform::OpenFile(lpszFileName, iNewFlags, openFlags & 0x1C);
+
+ m_hFile = ZipPlatform::OpenFile(lpszFileName, iNewFlags, openFlags & 0x70);
if (m_hFile == -1)
+ {
if (bThrow)
CZipException::Throw(errno, lpszFileName);
else
return false;
+ }
m_szFileName = lpszFileName;
return true;
}
@@ -99,31 +126,59 @@ bool CZipFile::Open(LPCTSTR lpszFileName, UINT openFlags, bool bThrow) void CZipFile::SetLength(ULONGLONG uNewLen)
{
- ZipPlatform::TruncateFile(m_hFile, uNewLen);
+ if (!ZipPlatform::TruncateFile(m_hFile, uNewLen))
+ {
+ ThrowError();
+ }
}
ZIP_FILE_USIZE CZipFile::GetPosition() const
{
+#ifdef FILE_FUNCTIONS_64B_BY_DEFAULT
#ifndef __GNUC__
ZIP_FILE_USIZE ret = _tell(m_hFile);
#else
ZIP_FILE_USIZE ret = lseek(m_hFile, 0, SEEK_CUR);
#endif
- if (ret == (ZIP_FILE_USIZE)-1)
- ThrowError();
- return ret;
+#else
+ #ifndef __GNUC__
+ ZIP_FILE_USIZE ret = (ZIP_FILE_USIZE)_telli64(m_hFile);
+ #else
+ ZIP_FILE_USIZE ret = (ZIP_FILE_USIZE)lseek64(m_hFile, 0, SEEK_CUR);
+ #endif
+#endif
+ if (ret == (ZIP_FILE_USIZE)-1)
+ ThrowError();
+ return ret;
}
ZIP_FILE_USIZE CZipFile::Seek(ZIP_FILE_SIZE dOff, int nFrom)
{
// restricted to signed
- ZIP_FILE_SIZE ret = (ZIP_FILE_SIZE)_lseek(m_hFile, (long)dOff, nFrom);
- if (ret == -1)
+#ifdef FILE_FUNCTIONS_64B_BY_DEFAULT
+ ZIP_FILE_USIZE ret = (ZIP_FILE_USIZE)_lseek(m_hFile, dOff, nFrom);
+#else
+ ZIP_FILE_USIZE ret = (ZIP_FILE_USIZE)_lseeki64(m_hFile, dOff, nFrom);
+#endif
+ if (ret == (ZIP_FILE_USIZE)-1)
ThrowError();
return (ZIP_FILE_USIZE)ret;
}
-void CZipFile::Flush()
+void CZipFile::Close()
+{
+ if (IsClosed())
+ return;
+ if (_close(m_hFile) != 0)
+ ThrowError();
+ else
+ {
+ m_szFileName.Empty();
+ m_hFile = -1;
+ }
+}
+
+void CZipFile::Flush()
{
if (!ZipPlatform::FlushFile(m_hFile))
ThrowError();
@@ -134,11 +189,39 @@ CZipFile::operator HANDLE() intptr_t fh = ZipPlatform::GetFileSystemHandle(m_hFile);
if (fh == -1)
ThrowError();
-#if _MSC_VER >= 1300
return (HANDLE)fh;
+}
+
+void CZipFile::Write(const void* lpBuf, size_t nCount)
+{
+ if (nCount == 0)
+ {
+ return;
+ }
+#ifdef _MSC_VER
+ if (_write(m_hFile, lpBuf, (unsigned int)nCount) != (int) nCount)
#else
- return (HANDLE)fh;
+ if (_write(m_hFile, lpBuf, nCount) != (int)nCount)
#endif
+ ThrowError();
+}
+
+size_t CZipFile::Read(void *lpBuf, size_t nCount)
+{
+ if (nCount == 0)
+ {
+ return 0;
+ }
+ errno = 0;
+#ifdef _MSC_VER
+ int ret = (int)_read(m_hFile, lpBuf, (unsigned int)nCount);
+#else
+ int ret = (int)_read(m_hFile, lpBuf, nCount);
+#endif
+ if (ret < (int) nCount && errno != 0)
+ ThrowError();
+ return ret;
+
}
#endif
|
