Main Page | Class List | Directories | File List | Class Members | File Members

file.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2005 by David J. Hardy.  All rights reserved.
00003  */
00004 
00023 #ifndef MDIO_FILE_H
00024 #define MDIO_FILE_H
00025 
00026 #include <stdio.h>
00027 
00028 #ifdef __cplusplus
00029 extern "C" {
00030 #endif
00031 
00032   enum {
00033     MDIO_ERROR = -1,          
00034     MDIO_LENGTH_ERRMSG = 240  /* length of error message diagnostic string */
00035   };
00036 
00038   enum {
00039     MDIO_FILE_TEXT   = 0x001, 
00040     MDIO_FILE_BINARY = 0x002, 
00041     MDIO_FILE_READ   = 0x004, 
00042     MDIO_FILE_WRITE  = 0x008  
00043   };
00044 
00046   enum {
00047     MDIO_ERROR_NONE,      
00048     MDIO_ERROR_WARN,      
00049     MDIO_ERROR_BADVAL,    
00050     MDIO_ERROR_NOMEM,     
00051     MDIO_ERROR_OPEN,      
00052     MDIO_ERROR_CLOSE,     
00053     MDIO_ERROR_READ,      
00054     MDIO_ERROR_WRITE,     
00055     MDIO_ERROR_SEEK,      
00056     MDIO_ERROR_SYNTAX,    
00057     MDIO_ERROR_UNXEOF,    
00058     MDIO_LENGTH_ERRORLIST /* number of error constants, marks end of list */
00059   };
00060 
00061   enum {
00062     MDIO_EOF = 0x001,          
00063     MDIO_SEEK_SET = SEEK_SET,  
00064     MDIO_SEEK_CUR = SEEK_CUR,  
00065     MDIO_SEEK_END = SEEK_END   
00066   };
00067 
00072   typedef struct mdio_File_t {
00073     FILE *file;
00074     const char *name;
00075     int (*errhandler)(struct mdio_File_t *);
00076     int filetype;
00077     int errnum;
00078     int bytenum;
00079     int linenum;
00080     int status;
00081     char errmsg[MDIO_LENGTH_ERRMSG];
00082   } mdio_File;
00083 
00084 
00085 /* constructor and destructor */
00086 
00093   mdio_File *mdio_createFile(void);
00094 
00095 
00100   void mdio_destroyFile(mdio_File *);
00101 
00102 
00103 /* basic file manipulation functions */
00104 
00120   int mdio_openFile(mdio_File *, const char *name, int filetype);
00121 
00122 
00127   int mdio_closeFile(mdio_File *);
00128 
00129 
00151   int mdio_readLineFile(mdio_File *, char **pbuf, int *pbuflen);
00152 
00153 
00169   int mdio_readTextFile(mdio_File *, char *buf, int buflen);
00170 
00171 
00182   int mdio_writeTextFile(mdio_File *, const char *buf);
00183 
00184 
00197   int mdio_readBinaryFile(mdio_File *, void *buffer, int elemsz, int n);
00198 
00199 
00212   int mdio_writeBinaryFile(mdio_File *, const void *buffer, int elemsz, int n);
00213 
00214 
00230   int mdio_seekFile(mdio_File *, long offset, int whence);
00231 
00232 
00236   int mdio_isEndOfFile(mdio_File *);
00237 
00238 
00256   int mdio_setErrorFile(mdio_File *, int errnum);
00257 
00258 
00268   int mdio_setErrorMessageFile(mdio_File *, int errnum, const char *msg);
00269 
00270 
00271 /* field access functions for error handling */
00272 
00288   void mdio_setErrorHandlerFile(mdio_File *, int (*errhandler)(mdio_File *));
00289 
00290 
00292   const char *mdio_getNameFile(mdio_File *);
00293 
00294 
00296   int mdio_getTypeFile(mdio_File *);
00297 
00298 
00300   int mdio_getErrorFile(mdio_File *);
00301 
00302 
00304   int mdio_getBytenumFile(mdio_File *);
00305 
00306 
00308   int mdio_getLinenumFile(mdio_File *);
00309 
00310 
00312   const char *mdio_getErrorMessageFile(mdio_File *);
00313 
00314 
00316   void mdio_resetErrorFile(mdio_File *);
00317 
00318 
00319 /* constructor and destructor for preallocated mdio_File object */
00320 
00326   int mdio_initializeFile(mdio_File *);
00327 
00328 
00334   void mdio_cleanupFile(mdio_File *);
00335 
00336 #ifdef __cplusplus
00337 }
00338 #endif
00339 
00340 #endif /* MDIO_FILE_H */

Generated on Mon Sep 26 10:55:18 2005 for MDX by  doxygen 1.4.4