home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / doom_i / program / dmreject.exe / SOURCE.ZIP / FILEIO.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-31  |  2.4 KB  |  100 lines

  1. //**********************************************************************************
  2. //    REJECT.EXE - Reject data table builder for DOOM
  3. //    Copyright (C) 1994 L.M.WITEK 
  4. //
  5. //    This program is free software; you can redistribute it and/or modify
  6. //    it under the terms of the GNU General Public License as published by
  7. //    the Free Software Foundation; either version 1, or (at your option)
  8. //    any later version.
  9. //
  10. //    This program is distributed in the hope that it will be useful,
  11. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. //    GNU General Public License for more details.
  14. //
  15. //    You should have received a copy of the GNU General Public License
  16. //    along with this program; if not, write to the Free Software
  17. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. //**********************************************************************************
  19.  
  20. #include "fileio.hpp"
  21.  
  22. BOOLEAN CFile::SetError (int exp)
  23. {
  24.      if (exp)
  25.      {
  26.           errorcode = errno;
  27.           return (bFALSE);
  28.      }
  29.      else
  30.      {
  31.           errorcode = 0;
  32.           return (bTRUE);
  33.      }
  34. }
  35.  
  36. void CFile::Close ()
  37. {
  38.      if (fh != -1)
  39.           close (fh);     
  40. }
  41.  
  42. BOOLEAN CFile::Open (XString name, int oflag)
  43. {
  44.      fh = open (name, oflag, S_IWRITE | S_IREAD);
  45.      return SetError (fh == -1);
  46. }
  47.  
  48. long CFile::Tell ()
  49. {
  50.      long pos = tell (fh);
  51.      SetError (pos == -1);
  52.      return pos;
  53. }
  54.  
  55. long CFile::Size ()
  56. {
  57.      long sz = filelength (fh);
  58.      SetError (sz == -1);
  59.      return sz;
  60. }
  61.  
  62. long CFile::Seek (long pos)
  63. {
  64.      long newpos = lseek (fh, pos, SEEK_SET);
  65.      SetError (newpos == -1);
  66.      return newpos;
  67. }
  68.  
  69. BOOLEAN CFile::IsOpen ()
  70. {
  71.      if (fh == -1)
  72.           return (bFALSE);
  73.      else
  74.           return (bTRUE);
  75. }
  76.  
  77. int CFile::Read (void *buffer, size_t size)
  78. {
  79.      int r = read (fh, buffer, size);
  80.      SetError (r == -1);
  81.      return r;
  82. }
  83.  
  84. MemHandle CFile::Read (size_t size)
  85. {
  86.      MemHandle buffer (size);
  87.      int r = read (fh, buffer, size);
  88.      SetError (r == -1);
  89.      if (r < size)
  90.           buffer.Shrink (r);
  91.      return buffer;
  92. }
  93.  
  94. int CFile::Write (MemHandle buffer)
  95. {
  96.      int written = write (fh, buffer, buffer.Size ());
  97.      SetError (written == -1);
  98.      return written;
  99. }
  100.