sub_section.cc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #include "file/sub_section.hh"
  9. #include "error/error.hh"
  10. w32 i4_sub_section_file::read (void *buffer, w32 rsize)
  11. {
  12. if (foffset-fstart+rsize>fsize) // don't allow reads past the sub section
  13. rsize=fstart+fsize-foffset;
  14. int rs=fp->read(buffer, rsize);
  15. foffset+=rs;
  16. return rs;
  17. }
  18. w32 i4_sub_section_file::write(const void *buffer, w32 size)
  19. {
  20. i4_error("don't write here");
  21. return 0;
  22. }
  23. w32 i4_sub_section_file::seek(w32 offset)
  24. {
  25. if (offset>=fsize)
  26. offset=fsize-1;
  27. foffset=fstart+offset;
  28. fp->seek(foffset);
  29. return foffset;
  30. }
  31. w32 i4_sub_section_file::size()
  32. {
  33. return fsize;
  34. }
  35. w32 i4_sub_section_file::tell()
  36. {
  37. return foffset-fstart;
  38. }
  39. i4_sub_section_file::i4_sub_section_file(i4_file_class *_fp, int start, int size)
  40. {
  41. fp=_fp;
  42. if (!fp)
  43. i4_error("no file");
  44. fp->seek(start);
  45. fsize=size;
  46. fstart=start;
  47. foffset=start;
  48. }
  49. i4_sub_section_file::~i4_sub_section_file()
  50. {
  51. if (fp)
  52. delete fp;
  53. }
  54. i4_bool i4_sub_section_file::async_read (void *buffer, w32 size,
  55. async_callback call,
  56. void *context)
  57. {
  58. if (foffset-fstart+size>fsize) // don't allow reads past the sub section
  59. size=fstart+fsize-foffset;
  60. foffset+=size;
  61. return fp->async_read(buffer, size, call, context);
  62. }