int ZipPlatform::OpenFile(LPCTSTR lpszFileName, UINT iMode, int iShareMode) { switch (iShareMode) { case (CZipFile::shareExclusive): iShareMode = SH_DENYRW; break; case (CZipFile::shareDenyRead): iShareMode = SH_DENYRD; break; case (CZipFile::shareDenyWrite): iShareMode = SH_DENYWR; break; default: iShareMode = SH_DENYNO; } #if _MSC_VER >= 1400 int handle; if (_tsopen_s(&handle, lpszFileName, iMode, iShareMode, S_IREAD | S_IWRITE /*required only when O_CREAT mode*/) != 0) return -1; else return handle; #else return _tsopen(lpszFileName, iMode, iShareMode, S_IREAD | S_IWRITE /*required only when O_CREAT mode*/); #endif }
bool CGZIPFile::Extract(LPCTSTR pszFilePath) { int fdOut = _tsopen(pszFilePath, _O_CREAT | _O_TRUNC | _O_WRONLY | _O_BINARY, _SH_DENYWR, _S_IREAD | _S_IWRITE); if (fdOut == -1) return false; bool bResult = true; const int iBuffSize = 32768; BYTE* pucBuff = new BYTE[iBuffSize]; while (!gzeof(m_gzFile)) { int iRead = gzread(m_gzFile, pucBuff, iBuffSize); if (iRead == 0) break; if (iRead < 0){ bResult = false; break; } if (write(fdOut, pucBuff, iRead) != iRead){ bResult = false; break; } } delete[] pucBuff; close(fdOut); if (!bResult) _tremove(pszFilePath); return bResult; }
int __cdecl _topen ( const _TSCHAR *path, int oflag, ... ) { va_list ap; int pmode; va_start(ap, oflag); pmode = va_arg(ap, int); va_end(ap); /* default sharing mode is DENY NONE */ return _tsopen(path, oflag, _SH_DENYNO, pmode); }
int ZipPlatform::OpenFile(LPCTSTR lpszFileName, UINT iMode, int iShareMode) { switch (iShareMode) { case (CZipFile::shareDenyWrite & CZipFile::shareDenyRead): iShareMode = SH_DENYRW; break; case (CZipFile::shareDenyRead): iShareMode = SH_DENYRD; break; case (CZipFile::shareDenyWrite): iShareMode = SH_DENYWR; break; default: iShareMode = SH_DENYNO; } return _tsopen(lpszFileName, iMode, iShareMode, S_IREAD | S_IWRITE /*required only when O_CREAT mode*/); }