aboutsummaryrefslogtreecommitdiff
path: root/C/7zStream.c
diff options
context:
space:
mode:
Diffstat (limited to 'C/7zStream.c')
-rw-r--r--C/7zStream.c67
1 files changed, 45 insertions, 22 deletions
diff --git a/C/7zStream.c b/C/7zStream.c
index 28a1460..74e75b6 100644
--- a/C/7zStream.c
+++ b/C/7zStream.c
@@ -1,5 +1,5 @@
1/* 7zStream.c -- 7z Stream functions 1/* 7zStream.c -- 7z Stream functions
22021-02-09 : Igor Pavlov : Public domain */ 22023-04-02 : Igor Pavlov : Public domain */
3 3
4#include "Precomp.h" 4#include "Precomp.h"
5 5
@@ -7,12 +7,33 @@
7 7
8#include "7zTypes.h" 8#include "7zTypes.h"
9 9
10SRes SeqInStream_Read2(const ISeqInStream *stream, void *buf, size_t size, SRes errorType) 10
11SRes SeqInStream_ReadMax(ISeqInStreamPtr stream, void *buf, size_t *processedSize)
12{
13 size_t size = *processedSize;
14 *processedSize = 0;
15 while (size != 0)
16 {
17 size_t cur = size;
18 const SRes res = ISeqInStream_Read(stream, buf, &cur);
19 *processedSize += cur;
20 buf = (void *)((Byte *)buf + cur);
21 size -= cur;
22 if (res != SZ_OK)
23 return res;
24 if (cur == 0)
25 return SZ_OK;
26 }
27 return SZ_OK;
28}
29
30/*
31SRes SeqInStream_Read2(ISeqInStreamPtr stream, void *buf, size_t size, SRes errorType)
11{ 32{
12 while (size != 0) 33 while (size != 0)
13 { 34 {
14 size_t processed = size; 35 size_t processed = size;
15 RINOK(ISeqInStream_Read(stream, buf, &processed)); 36 RINOK(ISeqInStream_Read(stream, buf, &processed))
16 if (processed == 0) 37 if (processed == 0)
17 return errorType; 38 return errorType;
18 buf = (void *)((Byte *)buf + processed); 39 buf = (void *)((Byte *)buf + processed);
@@ -21,42 +42,44 @@ SRes SeqInStream_Read2(const ISeqInStream *stream, void *buf, size_t size, SRes
21 return SZ_OK; 42 return SZ_OK;
22} 43}
23 44
24SRes SeqInStream_Read(const ISeqInStream *stream, void *buf, size_t size) 45SRes SeqInStream_Read(ISeqInStreamPtr stream, void *buf, size_t size)
25{ 46{
26 return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF); 47 return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
27} 48}
49*/
50
28 51
29SRes SeqInStream_ReadByte(const ISeqInStream *stream, Byte *buf) 52SRes SeqInStream_ReadByte(ISeqInStreamPtr stream, Byte *buf)
30{ 53{
31 size_t processed = 1; 54 size_t processed = 1;
32 RINOK(ISeqInStream_Read(stream, buf, &processed)); 55 RINOK(ISeqInStream_Read(stream, buf, &processed))
33 return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF; 56 return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;
34} 57}
35 58
36 59
37 60
38SRes LookInStream_SeekTo(const ILookInStream *stream, UInt64 offset) 61SRes LookInStream_SeekTo(ILookInStreamPtr stream, UInt64 offset)
39{ 62{
40 Int64 t = (Int64)offset; 63 Int64 t = (Int64)offset;
41 return ILookInStream_Seek(stream, &t, SZ_SEEK_SET); 64 return ILookInStream_Seek(stream, &t, SZ_SEEK_SET);
42} 65}
43 66
44SRes LookInStream_LookRead(const ILookInStream *stream, void *buf, size_t *size) 67SRes LookInStream_LookRead(ILookInStreamPtr stream, void *buf, size_t *size)
45{ 68{
46 const void *lookBuf; 69 const void *lookBuf;
47 if (*size == 0) 70 if (*size == 0)
48 return SZ_OK; 71 return SZ_OK;
49 RINOK(ILookInStream_Look(stream, &lookBuf, size)); 72 RINOK(ILookInStream_Look(stream, &lookBuf, size))
50 memcpy(buf, lookBuf, *size); 73 memcpy(buf, lookBuf, *size);
51 return ILookInStream_Skip(stream, *size); 74 return ILookInStream_Skip(stream, *size);
52} 75}
53 76
54SRes LookInStream_Read2(const ILookInStream *stream, void *buf, size_t size, SRes errorType) 77SRes LookInStream_Read2(ILookInStreamPtr stream, void *buf, size_t size, SRes errorType)
55{ 78{
56 while (size != 0) 79 while (size != 0)
57 { 80 {
58 size_t processed = size; 81 size_t processed = size;
59 RINOK(ILookInStream_Read(stream, buf, &processed)); 82 RINOK(ILookInStream_Read(stream, buf, &processed))
60 if (processed == 0) 83 if (processed == 0)
61 return errorType; 84 return errorType;
62 buf = (void *)((Byte *)buf + processed); 85 buf = (void *)((Byte *)buf + processed);
@@ -65,16 +88,16 @@ SRes LookInStream_Read2(const ILookInStream *stream, void *buf, size_t size, SRe
65 return SZ_OK; 88 return SZ_OK;
66} 89}
67 90
68SRes LookInStream_Read(const ILookInStream *stream, void *buf, size_t size) 91SRes LookInStream_Read(ILookInStreamPtr stream, void *buf, size_t size)
69{ 92{
70 return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF); 93 return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
71} 94}
72 95
73 96
74 97
75#define GET_LookToRead2 CLookToRead2 *p = CONTAINER_FROM_VTBL(pp, CLookToRead2, vt); 98#define GET_LookToRead2 Z7_CONTAINER_FROM_VTBL_TO_DECL_VAR_pp_vt_p(CLookToRead2)
76 99
77static SRes LookToRead2_Look_Lookahead(const ILookInStream *pp, const void **buf, size_t *size) 100static SRes LookToRead2_Look_Lookahead(ILookInStreamPtr pp, const void **buf, size_t *size)
78{ 101{
79 SRes res = SZ_OK; 102 SRes res = SZ_OK;
80 GET_LookToRead2 103 GET_LookToRead2
@@ -93,7 +116,7 @@ static SRes LookToRead2_Look_Lookahead(const ILookInStream *pp, const void **buf
93 return res; 116 return res;
94} 117}
95 118
96static SRes LookToRead2_Look_Exact(const ILookInStream *pp, const void **buf, size_t *size) 119static SRes LookToRead2_Look_Exact(ILookInStreamPtr pp, const void **buf, size_t *size)
97{ 120{
98 SRes res = SZ_OK; 121 SRes res = SZ_OK;
99 GET_LookToRead2 122 GET_LookToRead2
@@ -113,14 +136,14 @@ static SRes LookToRead2_Look_Exact(const ILookInStream *pp, const void **buf, si
113 return res; 136 return res;
114} 137}
115 138
116static SRes LookToRead2_Skip(const ILookInStream *pp, size_t offset) 139static SRes LookToRead2_Skip(ILookInStreamPtr pp, size_t offset)
117{ 140{
118 GET_LookToRead2 141 GET_LookToRead2
119 p->pos += offset; 142 p->pos += offset;
120 return SZ_OK; 143 return SZ_OK;
121} 144}
122 145
123static SRes LookToRead2_Read(const ILookInStream *pp, void *buf, size_t *size) 146static SRes LookToRead2_Read(ILookInStreamPtr pp, void *buf, size_t *size)
124{ 147{
125 GET_LookToRead2 148 GET_LookToRead2
126 size_t rem = p->size - p->pos; 149 size_t rem = p->size - p->pos;
@@ -134,7 +157,7 @@ static SRes LookToRead2_Read(const ILookInStream *pp, void *buf, size_t *size)
134 return SZ_OK; 157 return SZ_OK;
135} 158}
136 159
137static SRes LookToRead2_Seek(const ILookInStream *pp, Int64 *pos, ESzSeek origin) 160static SRes LookToRead2_Seek(ILookInStreamPtr pp, Int64 *pos, ESzSeek origin)
138{ 161{
139 GET_LookToRead2 162 GET_LookToRead2
140 p->pos = p->size = 0; 163 p->pos = p->size = 0;
@@ -153,9 +176,9 @@ void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead)
153 176
154 177
155 178
156static SRes SecToLook_Read(const ISeqInStream *pp, void *buf, size_t *size) 179static SRes SecToLook_Read(ISeqInStreamPtr pp, void *buf, size_t *size)
157{ 180{
158 CSecToLook *p = CONTAINER_FROM_VTBL(pp, CSecToLook, vt); 181 Z7_CONTAINER_FROM_VTBL_TO_DECL_VAR_pp_vt_p(CSecToLook)
159 return LookInStream_LookRead(p->realStream, buf, size); 182 return LookInStream_LookRead(p->realStream, buf, size);
160} 183}
161 184
@@ -164,9 +187,9 @@ void SecToLook_CreateVTable(CSecToLook *p)
164 p->vt.Read = SecToLook_Read; 187 p->vt.Read = SecToLook_Read;
165} 188}
166 189
167static SRes SecToRead_Read(const ISeqInStream *pp, void *buf, size_t *size) 190static SRes SecToRead_Read(ISeqInStreamPtr pp, void *buf, size_t *size)
168{ 191{
169 CSecToRead *p = CONTAINER_FROM_VTBL(pp, CSecToRead, vt); 192 Z7_CONTAINER_FROM_VTBL_TO_DECL_VAR_pp_vt_p(CSecToRead)
170 return ILookInStream_Read(p->realStream, buf, size); 193 return ILookInStream_Read(p->realStream, buf, size);
171} 194}
172 195