1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
19
#include <ndb_global.h>
22
* This class provides a file abstraction . It has operations
23
* to create, read, write and delete a file.
25
* @version #@ $Id: File.hpp,v 1.5 2002/04/26 13:15:38 ejonore Exp $
31
* Returns time for last contents modification of a file.
33
* @param aFileName a filename to check.
34
* @return the time for last contents modificaton of the file.
36
static time_t mtime(const char* aFileName);
39
* Returns true if the file exist.
41
* @param aFileName a filename to check.
42
* @return true if the file exists.
44
static bool exists(const char* aFileName);
47
* Returns the size of a file.
49
* @param f a pointer to a FILE descriptor.
50
* @return the size of the file.
52
static off_t size(FILE* f);
57
* @param currFileName the current name of the file.
58
* @param newFileName the new name of the file.
59
* @return true if successful.
61
static bool rename(const char* currFileName, const char* newFileName);
64
* Removes/deletes a file.
66
* @param aFileName the file to remove.
67
* @return true if successful.
69
static bool remove(const char* aFileName);
72
* Default constructor.
77
* Creates a new File with the specified filename and file mode.
78
* The real file itself will not be created unless open() is called!
80
* To see the available file modes use 'man 3 fopen'.
82
* @param aFileName a filename.
83
* @param mode the mode which the file should be opened/created with, default "r".
85
File_class(const char* aFileName, const char* mode = "r");
93
* Opens/creates the file. If open() fails then 'errno' and perror()
94
* should be used to determine the exact failure cause.
96
* @return true if successful. Check errno if unsuccessful.
101
* Opens/creates the file with the specified name and mode.
102
* If open() fails then 'errno' and perror() should be used to
103
* determine the exact failure cause.
105
* @param aFileName the file to open.
106
* @param mode the file mode to use.
107
* @return true if successful. Check errno if unsuccessful.
109
bool open(const char* aFileName, const char* mode);
114
* @return true if successful.
119
* Closes the file, i.e., the FILE descriptor is closed.
124
* Read from the file. See fread() for more info.
126
* @param buf the buffer to read into.
127
* @param itemSize the size of each item.
128
* @param nitems read max n number of items.
129
* @return 0 if successful.
131
int read(void* buf, size_t itemSize, size_t nitems) const;
134
* Read char from the file. See fread() for more info.
136
* @param buf the buffer to read into.
137
* @param start the start index of the buf.
138
* @param length the length of the buffer.
139
* @return 0 if successful.
141
int readChar(char* buf, long start, long length) const;
144
* Read chars from the file. See fread() for more info.
146
* @param buf the buffer to read into.
147
* @return 0 if successful.
149
int readChar(char* buf);
152
* Write to file. See fwrite() for more info.
154
* @param buf the buffer to read from.
155
* @param itemSize the size of each item.
156
* @param nitems write max n number of items.
157
* @return 0 if successful.
159
int write(const void* buf, size_t itemSize, size_t nitems);
162
* Write chars to file. See fwrite() for more info.
164
* @param buf the buffer to read from.
165
* @param start the start index of the buf.
166
* @param length the length of the buffer.
167
* @return 0 if successful.
169
int writeChar(const char* buf, long start, long length);
172
* Write chars to file. See fwrite() for more info.
174
* @param buf the buffer to read from.
175
* @return 0 if successful.
177
int writeChar(const char* buf);
180
* Returns the file size.
182
* @return the file size.
187
* Returns the filename.
189
* @return the filename.
191
const char* getName() const;
196
* @return 0 if successful.
202
char m_fileName[PATH_MAX];
203
const char* m_fileMode;
205
File_class (const File_class& aCopy);
206
File_class operator = (const File_class&);
207
bool operator == (const File_class&);