~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/include/util/File.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
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 */
 
15
 
 
16
#ifndef FILE_H
 
17
#define FILE_H
 
18
 
 
19
#include <ndb_global.h>
 
20
 
 
21
/**
 
22
 * This class provides a file abstraction . It has operations
 
23
 * to create, read, write and delete a file.
 
24
 *
 
25
 * @version #@ $Id: File.hpp,v 1.5 2002/04/26 13:15:38 ejonore Exp $
 
26
 */
 
27
class File_class
 
28
{
 
29
public:
 
30
  /**
 
31
   * Returns time for last contents modification of a file.
 
32
   *
 
33
   * @param aFileName a filename to check.
 
34
   * @return the time for last contents modificaton of the file.
 
35
   */
 
36
  static time_t mtime(const char* aFileName);      
 
37
 
 
38
  /**
 
39
   * Returns true if the file exist.
 
40
   *
 
41
   * @param aFileName a filename to check.
 
42
   * @return true if the file exists.
 
43
   */
 
44
  static bool exists(const char* aFileName);      
 
45
 
 
46
  /**
 
47
   * Returns the size of a file.
 
48
   *
 
49
   * @param f a pointer to a FILE descriptor.
 
50
   * @return the size of the file.
 
51
   */
 
52
  static off_t size(FILE* f);
 
53
 
 
54
  /**
 
55
   * Renames a file.
 
56
   *
 
57
   * @param currFileName the current name of the file.
 
58
   * @param newFileName the new name of the file.
 
59
   * @return true if successful.
 
60
   */
 
61
  static bool rename(const char* currFileName, const char* newFileName);
 
62
 
 
63
  /**
 
64
   * Removes/deletes a file.
 
65
   *
 
66
   * @param aFileName the file to remove.
 
67
   * @return true if successful.
 
68
   */
 
69
  static bool remove(const char* aFileName);      
 
70
  
 
71
  /**
 
72
   * Default constructor.
 
73
   */
 
74
  File_class();
 
75
 
 
76
  /**
 
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!
 
79
   *
 
80
   * To see the available file modes use 'man 3 fopen'.
 
81
   *
 
82
   * @param aFileName a filename.
 
83
   * @param mode the mode which the file should be opened/created with, default "r".
 
84
   */
 
85
  File_class(const char* aFileName, const char* mode = "r");
 
86
 
 
87
  /**
 
88
   * Destructor.
 
89
   */
 
90
  ~File_class();
 
91
 
 
92
  /**
 
93
   * Opens/creates the file. If open() fails then 'errno' and perror() 
 
94
   * should be used to determine the exact failure cause.
 
95
   *
 
96
   * @return true if successful. Check errno if unsuccessful.
 
97
   */
 
98
  bool open();
 
99
 
 
100
  /**
 
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.
 
104
   *
 
105
   * @param aFileName the file to open.
 
106
   * @param mode the file mode to use.
 
107
   * @return true if successful. Check errno if unsuccessful.   
 
108
   */
 
109
  bool open(const char* aFileName, const char* mode);
 
110
 
 
111
  /**
 
112
   * Removes the file.
 
113
   *
 
114
   * @return true if successful.
 
115
   */
 
116
  bool remove();
 
117
 
 
118
  /**
 
119
   * Closes the file, i.e., the FILE descriptor is closed.
 
120
   */
 
121
  bool close();
 
122
 
 
123
  /**
 
124
   * Read from the file. See fread() for more info.
 
125
   *
 
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.
 
130
   */
 
131
  int read(void* buf, size_t itemSize, size_t nitems) const;
 
132
 
 
133
  /**
 
134
   * Read char from the file. See fread() for more info.
 
135
   *
 
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.
 
140
   */
 
141
  int readChar(char* buf, long start, long length) const;  
 
142
 
 
143
  /**
 
144
   * Read chars from the file. See fread() for more info.
 
145
   *
 
146
   * @param buf the buffer to read into.
 
147
   * @return 0 if successful.
 
148
   */
 
149
  int readChar(char* buf);  
 
150
 
 
151
  /**
 
152
   * Write to file. See fwrite() for more info.
 
153
   *
 
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.
 
158
   */
 
159
  int write(const void* buf, size_t itemSize, size_t nitems);     
 
160
 
 
161
  /**
 
162
   * Write chars to file. See fwrite() for more info.
 
163
   *
 
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.
 
168
   */
 
169
  int writeChar(const char* buf, long start, long length);   
 
170
 
 
171
  /**
 
172
   * Write chars to file. See fwrite() for more info.
 
173
   *
 
174
   * @param buf the buffer to read from.
 
175
   * @return 0 if successful.
 
176
   */
 
177
  int writeChar(const char* buf); 
 
178
 
 
179
  /**
 
180
   * Returns the file size.
 
181
   *
 
182
   * @return the file size.
 
183
   */
 
184
  off_t size() const;
 
185
 
 
186
  /**
 
187
   * Returns the filename.
 
188
   *
 
189
   * @return the filename.
 
190
   */
 
191
  const char* getName() const;
 
192
 
 
193
  /**
 
194
   * Flush the buffer.
 
195
   *
 
196
   * @return 0 if successful.
 
197
   */
 
198
  int flush() const;
 
199
 
 
200
private:
 
201
  FILE* m_file;
 
202
  char m_fileName[PATH_MAX];
 
203
  const char* m_fileMode;
 
204
  /* Prohibit */
 
205
  File_class (const File_class& aCopy);
 
206
  File_class operator = (const File_class&); 
 
207
  bool operator == (const File_class&);
 
208
};
 
209
#endif
 
210