edelib: edelib/File.h Source File

edelib 1.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List

File.h
1 /*
2 * $Id: File.h 2967 2009-12-02 14:31:34Z karijes $
3 *
4 * File IO stream
5 * Copyright (c) 2005-2007 edelib authors
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef __EDELIB_FILE_H__
22 #define __EDELIB_FILE_H__
23
24 #include <stdio.h>
25 #include "String.h"
26
27 EDELIB_NS_BEGIN
28
33 enum FileErrors {
34 FILE_SUCCESS = 0,
35 FILE_EACCESS,
36 FILE_ENOENT,
37 FILE_EMFILE,
38 FILE_ENSPC,
39 FILE_FLAG
40 };
41
46 enum FileIOMode {
47 FIO_READ = (1<<1),
48 FIO_WRITE = (1<<2),
49 FIO_APPEND = (1<<3),
50 FIO_BINARY = (1<<4),
51 FIO_TRUNC = (1<<5)
52 };
53
74 class EDELIB_API File {
75 private:
76 FILE* fobj;
77 char* fname;
78 int fmode;
79 int errcode;
80 bool opened;
81 bool alloc;
82
83 File(const File&);
84 File& operator=(File&);
85
86 public:
90 File();
91
98 File(const char* n, int m);
99
104 ~File();
105
112 bool open(const char* fname, int mode = FIO_READ);
113
119 void close(void);
120
127 const char* name(void) const;
128
134 bool eof(void);
135
141 int getch(void);
142
151 int read(void* buff, int typesz, int buffsz);
152
166 int readline(char* buff, int buffsz);
167
173 int putch(int c);
174
183 int write(const void* buff, int typesz, int buffsz);
184
192 int write(const char* buff, unsigned int buffsz);
193
197 int write(const char* buff);
198
204 int printf(const char* fmt, ...);
205 };
206
212 EDELIB_API bool file_exists(const char* name) EDELIB_DEPRECATED;
213
219 EDELIB_API bool file_readable(const char* name) EDELIB_DEPRECATED;
220
226 EDELIB_API bool file_writeable(const char* name) EDELIB_DEPRECATED;
227
228
234 EDELIB_API bool file_executable(const char* name) EDELIB_DEPRECATED;
235
245 EDELIB_API bool file_remove(const char* name);
246
266 EDELIB_API bool file_copy(const char* src, const char* dest, bool exact = false);
267
275 EDELIB_API bool file_rename(const char* from, const char* to);
276
294 EDELIB_API String file_path(const char* fname, bool skip_link = false);
295
296 EDELIB_NS_END
297 #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