File.h
/*
* $Id: File.h 2967 2009-12-02 14:31:34Z karijes $
*
* File IO stream
* Copyright (c) 2005-2007 edelib authors
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __EDELIB_FILE_H__
#define __EDELIB_FILE_H__
#include <stdio.h>
#include "String.h"
EDELIB_NS_BEGIN
enum FileErrors {
FILE_SUCCESS = 0,
FILE_EACCESS,
FILE_ENOENT,
FILE_EMFILE,
FILE_ENSPC,
FILE_FLAG
};
enum FileIOMode {
FIO_READ = (1<<1),
FIO_WRITE = (1<<2),
FIO_APPEND = (1<<3),
FIO_BINARY = (1<<4),
FIO_TRUNC = (1<<5)
};
class EDELIB_API File {
private:
FILE* fobj;
char* fname;
int fmode;
int errcode;
bool opened;
bool alloc;
File(const File&);
File& operator=(File&);
public:
File();
File(const char* n, int m);
~File();
bool open(const char* fname, int mode = FIO_READ);
void close(void);
const char* name(void) const;
bool eof(void);
int getch(void);
int read(void* buff, int typesz, int buffsz);
int readline(char* buff, int buffsz);
int putch(int c);
int write(const void* buff, int typesz, int buffsz);
int write(const char* buff, unsigned int buffsz);
int write(const char* buff);
int printf(const char* fmt, ...);
};
EDELIB_API bool file_exists(const char* name) EDELIB_DEPRECATED;
EDELIB_API bool file_readable(const char* name) EDELIB_DEPRECATED;
EDELIB_API bool file_writeable(const char* name) EDELIB_DEPRECATED;
EDELIB_API bool file_executable(const char* name) EDELIB_DEPRECATED;
EDELIB_API bool file_remove(const char* name);
EDELIB_API bool file_copy(const char* src, const char* dest, bool exact = false);
EDELIB_API bool file_rename(const char* from, const char* to);
EDELIB_API String file_path(const char* fname, bool skip_link = false);
EDELIB_NS_END
#endif
edelib::FILE_ENSPC
no space left on device
Definition: File.h:38
edelib::FIO_READ
open file in read-only mode
Definition: File.h:47
edelib::FIO_TRUNC
truncate currently opened file
Definition: File.h:51
edelib::FILE_ENOENT
no such file
Definition: File.h:36
edelib::FILE_EMFILE
too many opened files
Definition: File.h:37
edelib::FileIOMode
FileIOMode
Open and write flags for File class.
Definition: File.h:46
edelib::File
A system file io stream.
Definition: File.h:74
edelib::FIO_APPEND
open file in append mode
Definition: File.h:49
edelib::FILE_SUCCESS
successful operation
Definition: File.h:34
edelib::FILE_EACCESS
permission denied
Definition: File.h:35
edelib::String
A (relatively simple) string implementation.
Definition: String.h:82
edelib::FileErrors
FileErrors
Error codes returned by File class.
Definition: File.h:33
edelib::FILE_FLAG
bad flag
Definition: File.h:39