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 */
16
#include <ndb_global.h>
27
File_class::mtime(const char* aFileName)
32
if (my_stat(aFileName, &stmp, MYF(0)) != NULL) {
40
File_class::exists(const char* aFileName)
44
return (my_stat(aFileName, &stmp, MYF(0))!=NULL);
48
File_class::size(FILE* f)
52
// Note that my_fstat behaves *differently* than my_stat. ARGGGHH!
53
if (my_fstat(fileno(f), &s, MYF(0)))
60
File_class::rename(const char* currFileName, const char* newFileName)
62
return ::rename(currFileName, newFileName) == 0 ? true : false;
65
File_class::remove(const char* aFileName)
67
return ::remove(aFileName) == 0 ? true : false;
70
File_class::File_class() :
76
File_class::File_class(const char* aFileName, const char* mode) :
80
BaseString::snprintf(m_fileName, PATH_MAX, aFileName);
86
return open(m_fileName, m_fileMode);
90
File_class::open(const char* aFileName, const char* mode)
92
if(m_fileName != aFileName){
94
* Only copy if it's not the same string
96
BaseString::snprintf(m_fileName, PATH_MAX, aFileName);
100
if ((m_file = ::fopen(m_fileName, m_fileMode))== NULL)
107
File_class::~File_class()
115
// Close the file first!
117
return File_class::remove(m_fileName);
129
retval = ::fclose(m_file);
130
while ( (retval != 0) && (errno == EINTR) ){
131
retval = ::fclose(m_file);
138
ndbout_c("ERROR: Close file error in File.cpp for %s",strerror(errno));
147
File_class::read(void* buf, size_t itemSize, size_t nitems) const
149
return ::fread(buf, itemSize, nitems, m_file);
153
File_class::readChar(char* buf, long start, long length) const
155
return ::fread((void*)&buf[start], 1, length, m_file);
159
File_class::readChar(char* buf)
161
return readChar(buf, 0, strlen(buf));
165
File_class::write(const void* buf, size_t size_arg, size_t nitems)
167
return ::fwrite(buf, size_arg, nitems, m_file);
171
File_class::writeChar(const char* buf, long start, long length)
173
return ::fwrite((const void*)&buf[start], sizeof(char), length, m_file);
177
File_class::writeChar(const char* buf)
179
return writeChar(buf, 0, ::strlen(buf));
183
File_class::size() const
185
return File_class::size(m_file);
189
File_class::getName() const
195
File_class::flush() const
197
return ::fflush(m_file);;