MCPcopy Create free account
hub / github.com/SmingHub/Sming / seekFrom

Method seekFrom

Sming/Core/Data/Stream/SectionStream.cpp:156–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154}
155
156int SectionStream::seekFrom(int offset, SeekOrigin origin)
157{
158 uint32_t newOffset = readOffset;
159
160 if(currentSectionIndex < 0 || currentSectionIndex >= sectionCount) {
161 return -1;
162 }
163 auto& sect = sections[currentSectionIndex];
164
165 switch(origin) {
166 case SeekOrigin::Start:
167 newOffset = sect.start + offset;
168 break;
169
170 case SeekOrigin::Current:
171 newOffset += offset;
172 break;
173
174 case SeekOrigin::End:
175 newOffset = uint32_t(sect.end() + offset);
176 break;
177
178 default:
179 return -1;
180 }
181
182 if(newOffset < sect.start || newOffset > sect.end()) {
183 return -1;
184 }
185
186 int pos = stream->seekFrom(newOffset, SeekOrigin::Start);
187 if(uint32_t(pos) != newOffset) {
188 return -1;
189 }
190
191 readOffset = newOffset;
192 sectionOffset = newOffset - sect.start;
193
194 if(newSection >= 0) {
195 // Prevent recursion
196 auto n = newSection;
197 newSection = -1;
198 gotoSection(n);
199 }
200
201 return sectionOffset;
202}

Callers 8

loadStreamMethod · 0.45
executeMethod · 0.45
executeMethod · 0.45
readMethod · 0.45
scanSourceMethod · 0.45
gotoSectionMethod · 0.45
nextSectionMethod · 0.45
readMemoryBlockMethod · 0.45

Calls 1

endMethod · 0.45

Tested by

no test coverage detected