source: golgotha/src/i4/file/sub_section.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 1.8 KB
Line 
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
13w32 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
23w32 i4_sub_section_file::write(const void *buffer, w32 size)
24{
25  i4_error("don't write here");
26  return 0;
27}
28
29
30w32 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
40w32 i4_sub_section_file::size()
41{
42  return fsize;
43}
44
45w32 i4_sub_section_file::tell()
46{
47  return foffset-fstart;
48}
49
50
51i4_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
63i4_sub_section_file::~i4_sub_section_file()
64{
65  if (fp)
66    delete fp;
67}
68
69
70i4_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}
Note: See TracBrowser for help on using the repository browser.