1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

clang format apply

This commit is contained in:
Leonid Fedorov
2022-01-21 16:43:49 +00:00
parent 6b6411229f
commit 04752ec546
1376 changed files with 393460 additions and 412662 deletions

View File

@ -33,250 +33,247 @@ using namespace std;
namespace idbdatafile
{
BufferedFile::BufferedFile(const char* fname, const char* mode, unsigned opts) :
IDBDataFile( fname ),
m_fp( 0 ),
m_buffer( 0 )
BufferedFile::BufferedFile(const char* fname, const char* mode, unsigned opts)
: IDBDataFile(fname), m_fp(0), m_buffer(0)
{
m_fp = fopen(fname, mode);
m_fp = fopen(fname, mode);
if ( m_fp == NULL )
{
throw std::runtime_error("unable to open Buffered file ");
}
if (m_fp == NULL)
{
throw std::runtime_error("unable to open Buffered file ");
}
applyOptions( opts );
applyOptions(opts);
}
void BufferedFile::applyOptions( unsigned opts )
void BufferedFile::applyOptions(unsigned opts)
{
if ( opts & IDBDataFile::USE_VBUF )
{
const int DEFAULT_BUFSIZ = 1 * 1024 * 1024;
m_buffer = new char[DEFAULT_BUFSIZ];
setvbuf(m_fp, m_buffer, _IOFBF, DEFAULT_BUFSIZ);
}
else if ( opts & IDBDataFile::USE_NOVBUF )
{
setvbuf(m_fp, NULL, _IONBF, 0);
}
if (opts & IDBDataFile::USE_VBUF)
{
const int DEFAULT_BUFSIZ = 1 * 1024 * 1024;
m_buffer = new char[DEFAULT_BUFSIZ];
setvbuf(m_fp, m_buffer, _IOFBF, DEFAULT_BUFSIZ);
}
else if (opts & IDBDataFile::USE_NOVBUF)
{
setvbuf(m_fp, NULL, _IONBF, 0);
}
}
BufferedFile::~BufferedFile()
{
close();
m_fp = 0;
delete [] m_buffer;
close();
m_fp = 0;
delete[] m_buffer;
}
ssize_t BufferedFile::pread(void* ptr, off64_t offset, size_t count)
{
ssize_t ret = 0;
int savedErrno;
ssize_t curpos = tell();
ssize_t ret = 0;
int savedErrno;
ssize_t curpos = tell();
seek(offset, SEEK_SET);
ret = read(ptr, count);
savedErrno = errno;
seek(curpos, SEEK_SET);
seek(offset, SEEK_SET);
ret = read(ptr, count);
savedErrno = errno;
seek(curpos, SEEK_SET);
if ( IDBLogger::isEnabled() )
IDBLogger::logRW("pread", m_fname, this, offset, count, ret);
if (IDBLogger::isEnabled())
IDBLogger::logRW("pread", m_fname, this, offset, count, ret);
errno = savedErrno;
return ret;
errno = savedErrno;
return ret;
}
ssize_t BufferedFile::read(void* ptr, size_t count)
{
ssize_t ret = 0;
ssize_t offset = tell();
int savedErrno = -1;
size_t progress = 0;
uint8_t* ptr8 = (uint8_t*) ptr;
ssize_t ret = 0;
ssize_t offset = tell();
int savedErrno = -1;
size_t progress = 0;
uint8_t* ptr8 = (uint8_t*)ptr;
while (progress < count)
while (progress < count)
{
ret = fread(ptr8 + progress, 1, count - progress, m_fp);
savedErrno = errno;
if (ret <= 0)
{
ret = fread(ptr8 + progress, 1, count - progress, m_fp);
savedErrno = errno;
if (ret <= 0)
{
if (ferror(m_fp))
{
errno = savedErrno;
return -1;
}
else if (feof(m_fp))
return progress;
}
progress += ret;
if (ferror(m_fp))
{
errno = savedErrno;
return -1;
}
else if (feof(m_fp))
return progress;
}
if ( IDBLogger::isEnabled() )
IDBLogger::logRW("read", m_fname, this, offset, count, progress);
progress += ret;
}
errno = savedErrno;
return progress;
if (IDBLogger::isEnabled())
IDBLogger::logRW("read", m_fname, this, offset, count, progress);
errno = savedErrno;
return progress;
}
ssize_t BufferedFile::write(const void* ptr, size_t count)
{
ssize_t ret = 0;
off64_t offset = tell();
int savedErrno = 0;
size_t progress = 0;
uint8_t* ptr8 = (uint8_t*) ptr;
ssize_t ret = 0;
off64_t offset = tell();
int savedErrno = 0;
size_t progress = 0;
uint8_t* ptr8 = (uint8_t*)ptr;
while (progress < count)
while (progress < count)
{
ret = fwrite(ptr8 + progress, 1, count - progress, m_fp);
savedErrno = errno;
if (ret <= 0 && ferror(m_fp))
{
ret = fwrite(ptr8 + progress, 1, count - progress, m_fp);
savedErrno = errno;
if (ret <= 0 && ferror(m_fp))
{
errno = savedErrno;
return -1;
}
else if (ret > 0)
progress += ret;
// can fwrite() continually return 0 with no error?
errno = savedErrno;
return -1;
}
else if (ret > 0)
progress += ret;
if ( IDBLogger::isEnabled() )
IDBLogger::logRW("write", m_fname, this, offset, count, progress);
// can fwrite() continually return 0 with no error?
}
errno = savedErrno;
return progress;
if (IDBLogger::isEnabled())
IDBLogger::logRW("write", m_fname, this, offset, count, progress);
errno = savedErrno;
return progress;
}
int BufferedFile::seek(off64_t offset, int whence)
{
int ret = 0;
int savedErrno;
int ret = 0;
int savedErrno;
#ifdef _MSC_VER
ret = _fseeki64(m_fp, offset, whence);
ret = _fseeki64(m_fp, offset, whence);
#else
ret = fseek(m_fp, offset, whence);
ret = fseek(m_fp, offset, whence);
#endif
savedErrno = errno;
savedErrno = errno;
if ( IDBLogger::isEnabled() )
IDBLogger::logSeek(m_fname, this, offset, whence, ret);
if (IDBLogger::isEnabled())
IDBLogger::logSeek(m_fname, this, offset, whence, ret);
errno = savedErrno;
return ret;
errno = savedErrno;
return ret;
}
int BufferedFile::truncate(off64_t length)
{
int ret = 0;
int savedErrno;
int ret = 0;
int savedErrno;
#ifdef _MSC_VER
ret = _chsize_s(_fileno(m_fp), length);
ret = _chsize_s(_fileno(m_fp), length);
#else
ret = ftruncate(fileno(m_fp), length);
ret = ftruncate(fileno(m_fp), length);
#endif
savedErrno = errno;
savedErrno = errno;
if ( IDBLogger::isEnabled() )
IDBLogger::logTruncate(m_fname, this, length, ret);
if (IDBLogger::isEnabled())
IDBLogger::logTruncate(m_fname, this, length, ret);
errno = savedErrno;
return ret;
errno = savedErrno;
return ret;
}
off64_t BufferedFile::size()
{
#ifdef _MSC_VER
return _filelengthi64(fileno(m_fp)); // Interestingly, implemented as fseek/ftell in the windows crt
return _filelengthi64(fileno(m_fp)); // Interestingly, implemented as fseek/ftell in the windows crt
#else
// going to calculate size 2 ways - first, via seek
off64_t length = -1;
off64_t here;
// going to calculate size 2 ways - first, via seek
off64_t length = -1;
off64_t here;
flockfile(m_fp);
flockfile(m_fp);
try
try
{
if ((here = ftell(m_fp)) > -1)
{
if ((here = ftell(m_fp)) > -1)
{
if (fseek(m_fp, 0, SEEK_END) > -1)
{
length = ftell(m_fp);
fseek(m_fp, here, SEEK_SET);
}
}
funlockfile(m_fp);
}
catch (...)
{
funlockfile(m_fp);
if (fseek(m_fp, 0, SEEK_END) > -1)
{
length = ftell(m_fp);
fseek(m_fp, here, SEEK_SET);
}
}
return length;
funlockfile(m_fp);
}
catch (...)
{
funlockfile(m_fp);
}
return length;
#endif
}
off64_t BufferedFile::tell()
{
#ifdef _MSC_VER
return _ftelli64(m_fp);
return _ftelli64(m_fp);
#else
return ftell(m_fp);
return ftell(m_fp);
#endif
}
int BufferedFile::flush()
{
int rc = fflush(m_fp);
int savedErrno = errno;
int rc = fflush(m_fp);
int savedErrno = errno;
if ( rc == 0 )
{
if (rc == 0)
{
#ifdef _MSC_VER
rc = _commit(_fileno(m_fp));
rc = _commit(_fileno(m_fp));
#else
rc = fsync( fileno( m_fp ) );
rc = fsync(fileno(m_fp));
#endif
savedErrno = errno;
}
savedErrno = errno;
}
if ( IDBLogger::isEnabled() )
IDBLogger::logNoArg(m_fname, this, "flush", rc);
if (IDBLogger::isEnabled())
IDBLogger::logNoArg(m_fname, this, "flush", rc);
errno = savedErrno;
return rc;
errno = savedErrno;
return rc;
}
time_t BufferedFile::mtime()
{
time_t ret = 0;
struct stat statbuf;
time_t ret = 0;
struct stat statbuf;
if (::fstat(fileno(m_fp), &statbuf) == 0)
ret = statbuf.st_mtime;
else
ret = (time_t) - 1;
if (::fstat(fileno(m_fp), &statbuf) == 0)
ret = statbuf.st_mtime;
else
ret = (time_t)-1;
return ret;
return ret;
}
int BufferedFile::close()
{
int ret = fclose(m_fp);
int savedErrno = errno;
int ret = fclose(m_fp);
int savedErrno = errno;
if ( IDBLogger::isEnabled() )
IDBLogger::logNoArg(m_fname, this, "close", ret);
if (IDBLogger::isEnabled())
IDBLogger::logNoArg(m_fname, this, "close", ret);
errno = savedErrno;
return ret;
errno = savedErrno;
return ret;
}
/**
@ -287,19 +284,19 @@ int BufferedFile::close()
*/
int BufferedFile::fallocate(int mode, off64_t offset, off64_t length)
{
int ret = 0;
int savedErrno = 0;
int ret = 0;
int savedErrno = 0;
ret = ::fallocate( fileno(m_fp), mode, offset, length );
savedErrno = errno;
ret = ::fallocate(fileno(m_fp), mode, offset, length);
savedErrno = errno;
if ( IDBLogger::isEnabled() )
{
IDBLogger::logNoArg(m_fname, this, "fallocate", errno);
}
if (IDBLogger::isEnabled())
{
IDBLogger::logNoArg(m_fname, this, "fallocate", errno);
}
errno = savedErrno;
return ret;
errno = savedErrno;
return ret;
}
}
} // namespace idbdatafile