/** * $Id: mfile.h,v 1.5 2002/10/21 08:37:21 plasmahh Exp $ * $Revision: 1.5 $ * $Author: plasmahh $ * $Date: 2002/10/21 08:37:21 $ */ #ifndef __MFILE_H #define __MFILE_H #ifndef __EXCEPTION_H #include "exception.h" #endif #include #include #include #include /** * @brief File class * * This class will implement some functions to access files more easily. It * will be extended as needed during developement * @todo Make calls much safer */ class mfile/*{{{*/ { private : /// POSIX Filedescriptor sint32 fd; /// The Name of the file mstring name; public: /** * Constructor. Tries to expand the filename, if not absolute. @param * mstring& ne Filename */ mfile( const mstring& ne ); /** * Opens the file with specified modes * @param int oflag File modes the file will be opened as for usual *nix open() * call. defaults to O_RDONLY=0 * @return true if the open was succesfull, false otherwise. error code will * be in error or can be printed with usual perror() * @note other possible values are O_WRONLY and O_RDWR or some others, @see * documentation of system call open() */ BOOL Open( sint32 oflag=0 ); /** * Closes the actual file, can be reopened with Open() * @return if close was successfull */ BOOL Close( void ); /** * Reads one line to the next newline in the file. If file ends * before a newline is found, the rest is inserted into the file. * The ending newline will not be set into the string * @return mstring next line in the file * @bug Does not work if line is larger than 2048, fix fix fix !!! */ mstring ReadLine( void ); /** * reads as the usual *nix system call, up to bytes bytes into the * buffer *buffer points to * @return int bytes read from file * @param char *buffer buffer to be written to * @param int bytes bytes to be read into the buffer */ inline sint32 Read( uchar8 * buffer, uint32 bytes) { return read(fd, buffer, bytes); } /** * reads up to bytes bytes into the string returned. If a \0 appears * within the buffer, the string will be only up to this \0 !!! * @param int bytes bytes to be read from file * @return mstring that holds the read data. */ mstring Read( uint32 bytes ); /** * @return int Current filedescriptor */ sint32 get_fd( void ) { return fd; } /** * @return if end of file has been reached, or if any data is left in the file */ BOOL Eof( void ); };/*}}}*/ #else #warning Multiple inclusion of mfile.h, please check your sources #endif /** *$Log: mfile.h,v $ *Revision 1.5 2002/10/21 08:37:21 plasmahh *beginning cleanup for smtpmap release 0.8-stable * *Revision 1.4 2002/05/23 19:48:08 plasmahh *removed some compiler warnings. *fixed one or two bugs. *refined include structure, for faster compiling *hm, what else ? don't know, I hope this works all ;) * *Revision 1.3 2002/05/14 16:31:13 plasmahh *Removed some compiler warnings *Added more code, hopefully fast ;) * *Revision 1.2 2002/05/13 21:32:57 plasmahh *implemented file class & readline *implemented additional in mstring * *Revision 1.1 2002/05/13 14:33:23 plasmahh *added file class * */