home *** CD-ROM | disk | FTP | other *** search
/ PC Media 4 / PC MEDIA CD04.iso / share / prog / res104 / source / file.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-30  |  2.5 KB  |  97 lines

  1. #if !defined (FILEdotH)
  2. #define FILEdotH
  3.  
  4.  
  5. #include <stdio.h>
  6. #include "portable.h"
  7.  
  8.  
  9. //*****
  10. //***** File manipulation class.
  11. //*****
  12.  
  13. class File
  14. {
  15.   FILE *fp;
  16.   char fName[PATH_MAX];
  17.   unsigned numErrors;
  18.   int reportErrors;
  19. public:
  20.   File(void);
  21.   File(char *filename, char *mode);
  22.   ~File(void);
  23.   inline unsigned status(void);            // returns true on error
  24.   int read(void *buf, biguint bytes);           // returns 0 on error
  25.   int write(void *buf, biguint bytes);          // returns 0 on error
  26.   int seek(bigint offset, int whence);          // returns 0 on error
  27.   inline int rewind(void);            // returns 0 on error
  28.   biguint position(void);                       // returns 0xFFFFFFFF on error
  29.   biguint size(void);                           // returns 0 on error
  30.   inline int eof(void);                         // returns true if at EOF
  31.   int open(char *filename, char *mode);        // returns 0 on error
  32.   int close(void);                // returns 0 on error
  33.   int gets(char *str, int maxChars);        // returns 0 on error
  34.   inline void quiet(void)               { reportErrors=0; }
  35.   inline void noisy(void)               { reportErrors=1; }
  36. };
  37.  
  38.  
  39.  
  40. /**************************************************************************
  41. *  Function:    File::status
  42. *
  43. *  Purpose:     Return a code indicating whether or not an error has
  44. *               occurred, and reset the number of errors to 0.
  45. *
  46. *  Entry:       N/A
  47. *
  48. *  Exit:        Returns non-zero if an error has occurred.
  49. **************************************************************************/
  50.  
  51. inline unsigned File::status(void)
  52. {
  53.   unsigned errors;
  54.  
  55.   errors = numErrors;            // store numErrors
  56.   numErrors = 0;            // reset numErrors to zero
  57.   return (errors);            // return old numErrors
  58. }
  59.  
  60.  
  61.  
  62. /**************************************************************************
  63. *  Function:    File::rewind
  64. *
  65. *  Purpose:     Seek to the beginning of the file.
  66. *
  67. *  Entry:       N/A
  68. *
  69. *  Exit:        Returns 0 on error.
  70. **************************************************************************/
  71.  
  72. inline int File::rewind(void)
  73. {
  74.   return (seek(0, SEEK_SET));
  75. }
  76.  
  77.  
  78.  
  79. /**************************************************************************
  80. *  Function:    File::eof
  81. *
  82. *  Purpose:     Determine if the file is at EOF or not.
  83. *
  84. *  Entry:       N/A
  85. *
  86. *  Exit:        Returns non-zero if the file is at EOF.
  87. **************************************************************************/
  88.  
  89. inline int File::eof(void)
  90. {
  91.   return (feof(fp));
  92. }
  93.  
  94.  
  95.  
  96. #endif
  97.