RAWFILE.H 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. ** Command & Conquer(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  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 3 of the License, or
  8. ** (at your option) 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, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* $Header: F:\projects\c&c\vcs\code\rawfile.h_v 2.16 16 Oct 1995 16:45:46 JOE_BOSTIC $ */
  19. /***********************************************************************************************
  20. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Westwood Library *
  24. * *
  25. * File Name : RAWFILE.H *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : August 8, 1994 *
  30. * *
  31. * Last Update : October 18, 1994 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * RawFileClass::File_Name -- Returns with the filename associate with the file object. *
  36. * RawFileClass::RawFileClass -- Default constructor for a file object. *
  37. * RawFileClass::Is_Open -- Checks to see if the file is open or not. *
  38. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  39. #ifndef RAWFILE_H
  40. #define RAWFILE_H
  41. #include <wwlib32.h>
  42. #include <limits.h>
  43. #include <errno.h>
  44. #include <wwfile.h>
  45. #ifdef NEVER
  46. /*
  47. ** This is a duplicate of the error numbers. The error handler for the RawFileClass handles
  48. ** these errors. If the error routine is overridden and additional errors are defined, then
  49. ** use numbers starting with 100. Note that these errors here are listed in numerical order.
  50. ** These errors are defined in the standard header file "ERRNO.H".
  51. */
  52. EZERO, // Non-error.
  53. EINVFNC, // Invalid function number.
  54. ENOFILE, // File not found.
  55. ENOENT=ENOFILE, // No such file or directory.
  56. ENOPATH, // Path not found.
  57. EMFILE, // Too many open files.
  58. EACCES, // Permission denied.
  59. EBADF, // Bad file number.
  60. ECONTR, // Memory blocks destroyed.
  61. ENOMEM, // Not enough core memory.
  62. EINVMEM, // Invalid memory block address.
  63. EINVENV, // Invalid environment.
  64. EINVFMT, // Invalid format.
  65. EINVACC, // Invalid access code.
  66. EINVDAT, // Invalid data.
  67. EFAULT, // Unknown error.
  68. EINVDRV, // Invalid drive specified.
  69. ENODEV=EINVDRV, // No such device.
  70. ECURDIR, // Attempt to remove CurDir.
  71. ENOTSAM, // Not same device.
  72. ENMFILE, // No more files.
  73. EINVAL, // Invalid argument.
  74. E2BIG, // Argument list too long.
  75. ENOEXEC, // exec format error.
  76. EXDEV, // Cross-device link.
  77. ENFILE, // Too many open files.
  78. ECHILD, // No child process.
  79. ENOTTY, // not used
  80. ETXTBSY, // not used
  81. EFBIG, // not used
  82. ENOSPC, // No space left on device.
  83. ESPIPE, // Illegal seek.
  84. EROFS, // Read-only file system.
  85. EMLINK, // not used
  86. EPIPE, // Broken pipe.
  87. EDOM, // Math argument.
  88. ERANGE, // Result too large.
  89. EEXIST, // File already exists.
  90. EDEADLOCK, // Locking violation.
  91. EPERM, // Operation not permitted.
  92. ESRCH, // not used
  93. EINTR, // Interrupted function call.
  94. EIO, // Input/output error.
  95. ENXIO, // No such device or address.
  96. EAGAIN, // Resource temporarily unavailable.
  97. ENOTBLK, // not used
  98. EBUSY, // Resource busy.
  99. ENOTDIR, // not used
  100. EISDIR, // not used
  101. EUCLEAN, // not used
  102. #endif
  103. /*
  104. ** This is the definition of the raw file class. It is derived from the abstract base FileClass
  105. ** and handles the interface to the low level DOS routines. This is the first class in the
  106. ** chain of derived file classes that actually performs a useful function. With this class,
  107. ** I/O is possible. More sophisticated features, such as packed files, CD-ROM support,
  108. ** file caching, and XMS/EMS memory support, are handled by derived classes.
  109. **
  110. ** Of particular importance is the need to override the error routine if more sophisticated
  111. ** error handling is required. This is more than likely if greater functionality is derived
  112. ** from this base class.
  113. */
  114. class RawFileClass : public FileClass
  115. {
  116. public:
  117. /*
  118. ** This is a record of the access rights used to open the file. These rights are
  119. ** used if the file object is duplicated.
  120. */
  121. int Rights;
  122. RawFileClass(char const *filename);
  123. RawFileClass(void);
  124. RawFileClass(RawFileClass const & f);
  125. RawFileClass & operator = (RawFileClass const & f);
  126. virtual ~RawFileClass(void);
  127. virtual char const * File_Name(void) const;
  128. virtual char const * Set_Name(char const *filename);
  129. virtual int Create(void);
  130. virtual int Delete(void);
  131. virtual int Is_Available(int forced=false);
  132. virtual int Is_Open(void) const;
  133. virtual int Open(char const *filename, int rights=READ);
  134. virtual int Open(int rights=READ);
  135. virtual long Read(void *buffer, long size);
  136. virtual long Seek(long pos, int dir=SEEK_CUR);
  137. virtual long Size(void);
  138. virtual long Write(void const *buffer, long size);
  139. virtual void Close(void);
  140. virtual void Error(int error, int canretry = false, char const * filename=NULL);
  141. protected:
  142. /*
  143. ** This function returns the largest size a low level DOS read or write may
  144. ** perform. Larger file transfers are performed in chunks of this size or less.
  145. */
  146. long Transfer_Block_Size(void) {return (long)((unsigned)UINT_MAX)-16L;};
  147. private:
  148. /*
  149. ** This is the low level DOS handle. A -1 indicates an empty condition.
  150. */
  151. int Handle;
  152. /*
  153. ** This points to the filename as a NULL terminated string. It may point to either a
  154. ** constant or an allocated string as indicated by the "Allocated" flag.
  155. */
  156. char const * Filename;
  157. /*
  158. ** Filenames that were assigned as part of the construction process
  159. ** are not allocated. It is assumed that the filename string is a
  160. ** constant in that case and thus making duplication unnecessary.
  161. ** This value will be non-zero if the filename has be allocated
  162. ** (using strdup()).
  163. */
  164. unsigned Allocated:1;
  165. };
  166. /***********************************************************************************************
  167. * RawFileClass::File_Name -- Returns with the filename associate with the file object. *
  168. * *
  169. * Use this routine to determine what filename is associated with this file object. If no *
  170. * filename has yet been assigned, then this routing will return NULL. *
  171. * *
  172. * INPUT: none *
  173. * *
  174. * OUTPUT: Returns with a pointer to the file name associated with this file object or NULL *
  175. * if one doesn't exist. *
  176. * *
  177. * WARNINGS: none *
  178. * *
  179. * HISTORY: *
  180. ;* 10/18/1994 JLB : Created. *
  181. *=============================================================================================*/
  182. inline char const * RawFileClass::File_Name(void) const
  183. {
  184. return(Filename);
  185. }
  186. /***********************************************************************************************
  187. * RawFileClass::RawFileClass -- Default constructor for a file object. *
  188. * *
  189. * This constructs a null file object. A null file object has no file handle or filename *
  190. * associated with it. In order to use a file object created in this fashion it must be *
  191. * assigned a name and then opened. *
  192. * *
  193. * INPUT: none *
  194. * *
  195. * OUTPUT: none *
  196. * *
  197. * WARNINGS: none *
  198. * *
  199. * HISTORY: *
  200. ;* 10/18/1994 JLB : Created. *
  201. *=============================================================================================*/
  202. inline RawFileClass::RawFileClass(void) : Handle(-1), Filename(0), Allocated(false)
  203. {
  204. }
  205. /***********************************************************************************************
  206. * RawFileClass::Is_Open -- Checks to see if the file is open or not. *
  207. * *
  208. * Use this routine to determine if the file is open. It returns true if it is. *
  209. * *
  210. * INPUT: none *
  211. * *
  212. * OUTPUT: bool; Is the file open? *
  213. * *
  214. * *
  215. * WARNINGS: none *
  216. * *
  217. * HISTORY: *
  218. ;* 10/18/1994 JLB : Created. *
  219. *=============================================================================================*/
  220. inline int RawFileClass::Is_Open(void) const
  221. {
  222. return (Handle >= 0);
  223. }
  224. #endif