edelib 2.1.0
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
27EDELIB_NS_BEGIN
28
40};
41
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
74class EDELIB_API File {
75private:
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
86public:
91
98 File(const char* n, int m);
99
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
212EDELIB_API bool file_exists(const char* name) EDELIB_DEPRECATED;
213
219EDELIB_API bool file_readable(const char* name) EDELIB_DEPRECATED;
220
226EDELIB_API bool file_writeable(const char* name) EDELIB_DEPRECATED;
227
228
234EDELIB_API bool file_executable(const char* name) EDELIB_DEPRECATED;
235
245EDELIB_API bool file_remove(const char* name);
246
266EDELIB_API bool file_copy(const char* src, const char* dest, bool exact = false);
267
275EDELIB_API bool file_rename(const char* from, const char* to);
276
294EDELIB_API String file_path(const char* fname, bool skip_link = false);
295
296EDELIB_NS_END
297#endif
A system file io stream.
Definition: File.h:74
bool file_writeable(const char *name)
bool eof(void)
bool file_exists(const char *name)
bool file_remove(const char *name)
int read(void *buff, int typesz, int buffsz)
bool file_copy(const char *src, const char *dest, bool exact=false)
int putch(int c)
int write(const char *buff, unsigned int buffsz)
File(const char *n, int m)
const char * name(void) const
int printf(const char *fmt,...)
int readline(char *buff, int buffsz)
void close(void)
bool open(const char *fname, int mode=FIO_READ)
bool file_readable(const char *name)
String file_path(const char *fname, bool skip_link=false)
int write(const char *buff)
bool file_executable(const char *name)
bool file_rename(const char *from, const char *to)
int write(const void *buff, int typesz, int buffsz)
int getch(void)
A (relatively simple) string implementation.
Definition: String.h:82
FileErrors
Error codes returned by File class.
Definition: File.h:33
@ FILE_EACCESS
permission denied
Definition: File.h:35
@ FILE_SUCCESS
successful operation
Definition: File.h:34
@ FILE_ENSPC
no space left on device
Definition: File.h:38
@ FILE_ENOENT
no such file
Definition: File.h:36
@ FILE_EMFILE
too many opened files
Definition: File.h:37
@ FILE_FLAG
bad flag
Definition: File.h:39
FileIOMode
Open and write flags for File class.
Definition: File.h:46
@ FIO_TRUNC
truncate currently opened file
Definition: File.h:51
@ FIO_READ
open file in read-only mode
Definition: File.h:47
@ FIO_APPEND
open file in append mode
Definition: File.h:49