aboutsummaryrefslogtreecommitdiff
path: root/CPP/7zip/Common/FileStreams.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/7zip/Common/FileStreams.cpp129
1 files changed, 126 insertions, 3 deletions
diff --git a/CPP/7zip/Common/FileStreams.cpp b/CPP/7zip/Common/FileStreams.cpp
index 4298636..f90e280 100644
--- a/CPP/7zip/Common/FileStreams.cpp
+++ b/CPP/7zip/Common/FileStreams.cpp
@@ -11,14 +11,26 @@
11#include <grp.h> 11#include <grp.h>
12#include <pwd.h> 12#include <pwd.h>
13 13
14/*
15inclusion of <sys/sysmacros.h> by <sys/types.h> is deprecated since glibc 2.25.
16Since glibc 2.3.3, macros have been aliases for three GNU-specific
17functions: gnu_dev_makedev(), gnu_dev_major(), and gnu_dev_minor()
18
19Warning in GCC:
20In the GNU C Library, "major" is defined by <sys/sysmacros.h>.
21For historical compatibility, it is currently defined by
22<sys/types.h> as well, but we plan to remove this soon.
23To use "major", include <sys/sysmacros.h> directly.
24If you did not intend to use a system-defined macro "major",
25you should undefine it after including <sys/types.h>
26*/
14// for major()/minor(): 27// for major()/minor():
28#if defined(__APPLE__) || defined(__DragonFly__) || \
29 defined(BSD) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
15#include <sys/types.h> 30#include <sys/types.h>
16#if defined(__FreeBSD__) || defined(BSD) || defined(__APPLE__)
17#else 31#else
18#ifndef major
19#include <sys/sysmacros.h> 32#include <sys/sysmacros.h>
20#endif 33#endif
21#endif
22 34
23#endif // _WIN32 35#endif // _WIN32
24 36
@@ -85,6 +97,8 @@ CInFileStream::~CInFileStream()
85 97
86Z7_COM7F_IMF(CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)) 98Z7_COM7F_IMF(CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize))
87{ 99{
100 // printf("\nCInFileStream::Read size=%d, VirtPos=%8d\n", (unsigned)size, (int)VirtPos);
101
88 #ifdef Z7_FILE_STREAMS_USE_WIN_FILE 102 #ifdef Z7_FILE_STREAMS_USE_WIN_FILE
89 103
90 #ifdef Z7_DEVICE_FILE 104 #ifdef Z7_DEVICE_FILE
@@ -205,6 +219,10 @@ Z7_COM7F_IMF(CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)
205 219
206 { 220 {
207 const DWORD error = ::GetLastError(); 221 const DWORD error = ::GetLastError();
222#if 0
223 if (File.IsStdStream && error == ERROR_BROKEN_PIPE)
224 return S_OK; // end of stream
225#endif
208 if (Callback) 226 if (Callback)
209 return Callback->InFileStream_On_Error(CallbackRef, error); 227 return Callback->InFileStream_On_Error(CallbackRef, error);
210 if (error == 0) 228 if (error == 0)
@@ -227,13 +245,35 @@ Z7_COM7F_IMF(CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSi
227#else 245#else
228Z7_COM7F_IMF(CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)) 246Z7_COM7F_IMF(CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize))
229{ 247{
248 // printf("\nCStdInFileStream::Read size = %d\n", (unsigned)size);
230 #ifdef _WIN32 249 #ifdef _WIN32
231 250
232 DWORD realProcessedSize; 251 DWORD realProcessedSize;
233 UInt32 sizeTemp = (1 << 20); 252 UInt32 sizeTemp = (1 << 20);
234 if (sizeTemp > size) 253 if (sizeTemp > size)
235 sizeTemp = size; 254 sizeTemp = size;
255 /* in GUI mode : GetStdHandle(STD_INPUT_HANDLE) returns NULL,
256 and it doesn't set LastError. */
257 /*
258 SetLastError(0);
259 const HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
260 if (!h || h == INVALID_HANDLE_VALUE)
261 {
262 if (processedSize)
263 *processedSize = 0;
264 if (GetLastError() == 0)
265 SetLastError(ERROR_INVALID_HANDLE);
266 return GetLastError_noZero_HRESULT();
267 }
268 */
236 BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE), data, sizeTemp, &realProcessedSize, NULL); 269 BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE), data, sizeTemp, &realProcessedSize, NULL);
270
271 /*
272 printf("\nCInFileStream::Read: size=%d, processed=%8d res=%d 4rror=%3d\n",
273 (unsigned)size, (int)realProcessedSize,
274 (int)res, GetLastError());
275 */
276
237 if (processedSize) 277 if (processedSize)
238 *processedSize = realProcessedSize; 278 *processedSize = realProcessedSize;
239 if (res == FALSE && GetLastError() == ERROR_BROKEN_PIPE) 279 if (res == FALSE && GetLastError() == ERROR_BROKEN_PIPE)
@@ -261,8 +301,62 @@ Z7_COM7F_IMF(CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSi
261 301
262#endif 302#endif
263 303
304
305/*
306bool CreateStdInStream(CMyComPtr<ISequentialInStream> &str)
307{
308#if 0
309 CInFileStream *inStreamSpec = new CInFileStream;
310 CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);;
311 if (!inStreamSpec->OpenStdIn())
312 return false;
313 if (!inStreamSpec->File.IsStdPipeStream)
314 str = inStreamLoc.Detach();
315 else
316#endif
317 str = new CStdInFileStream;
318 return true;
319}
320*/
321
322#if 0
323bool CInFileStream::OpenStdIn()
324{
325 _info_WasLoaded = false;
326 // Sleep(100);
327 bool res = File.AttachStdIn();
328 if (!res)
329 return false;
330#if 1
331 CStreamFileProps props;
332 if (GetProps2(&props) != S_OK)
333 {
334 // we can ignore that error
335 return false;
336 }
337 // we can't use Size, because Size can be set for pipe streams for some value.
338 // Seek() sees only current chunk in pipe buffer.
339 // So Seek() can move across only current unread chunk.
340 // But after reading that chunk. it can't move position back.
341 // We need safe check that shows that we can use seek (non-pipe mode)
342 // Is it safe check that shows that pipe mode was used?
343 File.IsStdPipeStream = (props.VolID == 0);
344 // && FILETIME_IsZero(props.CTime)
345 // && FILETIME_IsZero(props.ATime)
346 // && FILETIME_IsZero(props.MTime);
347#endif
348 // printf("\n######## pipe=%d", (unsigned)File.IsStdPipeStream);
349 return true;
350}
351#endif
352
353
264Z7_COM7F_IMF(CInFileStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)) 354Z7_COM7F_IMF(CInFileStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition))
265{ 355{
356 /*
357 printf("\nCInFileStream::Seek seekOrigin=%d, offset=%8d, VirtPos=%8d\n",
358 (unsigned)seekOrigin, (int)offset, (int)VirtPos);
359 */
266 if (seekOrigin >= 3) 360 if (seekOrigin >= 3)
267 return STG_E_INVALIDFUNCTION; 361 return STG_E_INVALIDFUNCTION;
268 362
@@ -463,6 +557,31 @@ Z7_COM7F_IMF(CInFileStream::ReloadProps())
463 _info_WasLoaded = File.GetFileInformation(&_info); 557 _info_WasLoaded = File.GetFileInformation(&_info);
464 if (!_info_WasLoaded) 558 if (!_info_WasLoaded)
465 return GetLastError_HRESULT(); 559 return GetLastError_HRESULT();
560#ifdef _WIN32
561#if 0
562 printf(
563 "\ndwFileAttributes = %8x"
564 "\nftCreationTime = %8x"
565 "\nftLastAccessTime = %8x"
566 "\nftLastWriteTime = %8x"
567 "\ndwVolumeSerialNumber = %8x"
568 "\nnFileSizeHigh = %8x"
569 "\nnFileSizeLow = %8x"
570 "\nnNumberOfLinks = %8x"
571 "\nnFileIndexHigh = %8x"
572 "\nnFileIndexLow = %8x \n",
573 (unsigned)_info.dwFileAttributes,
574 (unsigned)_info.ftCreationTime.dwHighDateTime,
575 (unsigned)_info.ftLastAccessTime.dwHighDateTime,
576 (unsigned)_info.ftLastWriteTime.dwHighDateTime,
577 (unsigned)_info.dwVolumeSerialNumber,
578 (unsigned)_info.nFileSizeHigh,
579 (unsigned)_info.nFileSizeLow,
580 (unsigned)_info.nNumberOfLinks,
581 (unsigned)_info.nFileIndexHigh,
582 (unsigned)_info.nFileIndexLow);
583#endif
584#endif
466 return S_OK; 585 return S_OK;
467} 586}
468 587
@@ -471,6 +590,7 @@ Z7_COM7F_IMF(CInFileStream::ReloadProps())
471 590
472Z7_COM7F_IMF(CInFileStream::GetProps(UInt64 *size, FILETIME *cTime, FILETIME *aTime, FILETIME *mTime, UInt32 *attrib)) 591Z7_COM7F_IMF(CInFileStream::GetProps(UInt64 *size, FILETIME *cTime, FILETIME *aTime, FILETIME *mTime, UInt32 *attrib))
473{ 592{
593 // printf("\nCInFileStream::GetProps VirtPos = %8d\n", (int)VirtPos);
474 if (!_info_WasLoaded) 594 if (!_info_WasLoaded)
475 { 595 {
476 RINOK(ReloadProps()) 596 RINOK(ReloadProps())
@@ -495,6 +615,7 @@ Z7_COM7F_IMF(CInFileStream::GetProps(UInt64 *size, FILETIME *cTime, FILETIME *aT
495 615
496Z7_COM7F_IMF(CInFileStream::GetProps2(CStreamFileProps *props)) 616Z7_COM7F_IMF(CInFileStream::GetProps2(CStreamFileProps *props))
497{ 617{
618 // printf("\nCInFileStream::GetProps2 VirtPos = %8d\n", (int)VirtPos);
498 if (!_info_WasLoaded) 619 if (!_info_WasLoaded)
499 { 620 {
500 RINOK(ReloadProps()) 621 RINOK(ReloadProps())
@@ -535,6 +656,7 @@ Z7_COM7F_IMF(CInFileStream::GetProps2(CStreamFileProps *props))
535 656
536Z7_COM7F_IMF(CInFileStream::GetProperty(PROPID propID, PROPVARIANT *value)) 657Z7_COM7F_IMF(CInFileStream::GetProperty(PROPID propID, PROPVARIANT *value))
537{ 658{
659 // printf("\nCInFileStream::GetProperty VirtPos = %8d propID = %3d\n", (int)VirtPos, propID);
538 if (!_info_WasLoaded) 660 if (!_info_WasLoaded)
539 { 661 {
540 RINOK(ReloadProps()) 662 RINOK(ReloadProps())
@@ -648,6 +770,7 @@ Z7_COM7F_IMF(CInFileStream::GetProperty(PROPID propID, PROPVARIANT *value))
648 } 770 }
649 break; 771 break;
650 } 772 }
773 default: break;
651 } 774 }
652 } 775 }
653 prop.Detach(value); 776 prop.Detach(value);