1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #include "file/sub_section.hh"
|
---|
10 | #include "error/error.hh"
|
---|
11 |
|
---|
12 |
|
---|
13 | w32 i4_sub_section_file::read (void *buffer, w32 rsize)
|
---|
14 | {
|
---|
15 | if (foffset-fstart+rsize>fsize) // don't allow reads past the sub section
|
---|
16 | rsize=fstart+fsize-foffset;
|
---|
17 |
|
---|
18 | int rs=fp->read(buffer, rsize);
|
---|
19 | foffset+=rs;
|
---|
20 | return rs;
|
---|
21 | }
|
---|
22 |
|
---|
23 | w32 i4_sub_section_file::write(const void *buffer, w32 size)
|
---|
24 | {
|
---|
25 | i4_error("don't write here");
|
---|
26 | return 0;
|
---|
27 | }
|
---|
28 |
|
---|
29 |
|
---|
30 | w32 i4_sub_section_file::seek(w32 offset)
|
---|
31 | {
|
---|
32 | if (offset>=fsize)
|
---|
33 | offset=fsize-1;
|
---|
34 |
|
---|
35 | foffset=fstart+offset;
|
---|
36 | fp->seek(foffset);
|
---|
37 | return foffset;
|
---|
38 | }
|
---|
39 |
|
---|
40 | w32 i4_sub_section_file::size()
|
---|
41 | {
|
---|
42 | return fsize;
|
---|
43 | }
|
---|
44 |
|
---|
45 | w32 i4_sub_section_file::tell()
|
---|
46 | {
|
---|
47 | return foffset-fstart;
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | i4_sub_section_file::i4_sub_section_file(i4_file_class *_fp, int start, int size)
|
---|
52 | {
|
---|
53 | fp=_fp;
|
---|
54 | if (!fp)
|
---|
55 | i4_error("no file");
|
---|
56 |
|
---|
57 | fp->seek(start);
|
---|
58 | fsize=size;
|
---|
59 | fstart=start;
|
---|
60 | foffset=start;
|
---|
61 | }
|
---|
62 |
|
---|
63 | i4_sub_section_file::~i4_sub_section_file()
|
---|
64 | {
|
---|
65 | if (fp)
|
---|
66 | delete fp;
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | i4_bool i4_sub_section_file::async_read (void *buffer, w32 size,
|
---|
71 | async_callback call,
|
---|
72 | void *context)
|
---|
73 | {
|
---|
74 | if (foffset-fstart+size>fsize) // don't allow reads past the sub section
|
---|
75 | size=fstart+fsize-foffset;
|
---|
76 |
|
---|
77 |
|
---|
78 | foffset+=size;
|
---|
79 | return fp->async_read(buffer, size, call, context);
|
---|
80 | }
|
---|