edelib 2.0.0

edelib/File.h

00001 /*
00002  * $Id: File.h 2967 2009-12-02 14:31:34Z karijes $
00003  *
00004  * File IO stream
00005  * Copyright (c) 2005-2007 edelib authors
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00021 #ifndef __EDELIB_FILE_H__
00022 #define __EDELIB_FILE_H__
00023 
00024 #include <stdio.h>
00025 #include "String.h"
00026 
00027 EDELIB_NS_BEGIN
00028 
00033 enum FileErrors {
00034         FILE_SUCCESS = 0,  
00035         FILE_EACCESS,      
00036         FILE_ENOENT,       
00037         FILE_EMFILE,       
00038         FILE_ENSPC,        
00039         FILE_FLAG          
00040 };
00041 
00046 enum FileIOMode {
00047         FIO_READ    = (1<<1),          
00048         FIO_WRITE   = (1<<2),          
00049         FIO_APPEND  = (1<<3),          
00050         FIO_BINARY  = (1<<4),          
00051         FIO_TRUNC   = (1<<5)           
00052 };
00053 
00074 class EDELIB_API File {
00075 private:
00076         FILE* fobj;
00077         char* fname;
00078         int fmode;
00079         int errcode;
00080         bool opened;
00081         bool alloc;
00082 
00083         File(const File&);
00084         File& operator=(File&);
00085 
00086 public:
00090         File();
00091 
00098         File(const char* n, int m);
00099 
00104         ~File();
00105 
00112         bool open(const char* fname, int mode = FIO_READ);
00113 
00119         void close(void);
00120 
00127         const char* name(void) const;
00128 
00134         bool eof(void);
00135 
00141         int getch(void);
00142 
00151         int read(void* buff, int typesz, int buffsz);
00152 
00166         int readline(char* buff, int buffsz);
00167 
00173         int putch(int c);
00174 
00183         int write(const void* buff, int typesz, int buffsz);
00184 
00192         int write(const char* buff, unsigned int buffsz);
00193 
00197         int write(const char* buff);
00198 
00204         int printf(const char* fmt, ...);
00205 };
00206 
00212 EDELIB_API bool file_exists(const char* name) EDELIB_DEPRECATED;
00213 
00219 EDELIB_API bool file_readable(const char* name) EDELIB_DEPRECATED;
00220 
00226 EDELIB_API bool file_writeable(const char* name) EDELIB_DEPRECATED;
00227 
00228 
00234 EDELIB_API bool file_executable(const char* name) EDELIB_DEPRECATED;
00235 
00245 EDELIB_API bool file_remove(const char* name);
00246 
00266 EDELIB_API bool file_copy(const char* src, const char* dest, bool exact = false);
00267 
00275 EDELIB_API bool file_rename(const char* from, const char* to);
00276 
00294 EDELIB_API String file_path(const char* fname, bool skip_link = false);
00295 
00296 EDELIB_NS_END
00297 #endif