summaryrefslogtreecommitdiffstats
path: root/src/OSSupport
diff options
context:
space:
mode:
authorLogicParrot <LogicParrot@users.noreply.github.com>2016-02-05 22:45:45 +0100
committerLogicParrot <LogicParrot@users.noreply.github.com>2016-02-05 22:50:18 +0100
commitca6ef58b1ee8521e4b940ee4883dee714960e413 (patch)
tree8532add455224b07c07a759e3d906f50c0695888 /src/OSSupport
parentMerge pull request #2972 from marvinkopf/PlayerAutoComplete (diff)
downloadcuberite-ca6ef58b1ee8521e4b940ee4883dee714960e413.tar
cuberite-ca6ef58b1ee8521e4b940ee4883dee714960e413.tar.gz
cuberite-ca6ef58b1ee8521e4b940ee4883dee714960e413.tar.bz2
cuberite-ca6ef58b1ee8521e4b940ee4883dee714960e413.tar.lz
cuberite-ca6ef58b1ee8521e4b940ee4883dee714960e413.tar.xz
cuberite-ca6ef58b1ee8521e4b940ee4883dee714960e413.tar.zst
cuberite-ca6ef58b1ee8521e4b940ee4883dee714960e413.zip
Diffstat (limited to 'src/OSSupport')
-rw-r--r--src/OSSupport/CriticalSection.cpp4
-rw-r--r--src/OSSupport/CriticalSection.h12
-rw-r--r--src/OSSupport/Errors.cpp18
-rw-r--r--src/OSSupport/Event.h2
-rw-r--r--src/OSSupport/File.cpp42
-rw-r--r--src/OSSupport/File.h50
-rw-r--r--src/OSSupport/GZipFile.cpp4
-rw-r--r--src/OSSupport/GZipFile.h14
-rw-r--r--src/OSSupport/IsThread.h2
-rw-r--r--src/OSSupport/Queue.h12
-rw-r--r--src/OSSupport/TCPLinkImpl.cpp2
11 files changed, 81 insertions, 81 deletions
diff --git a/src/OSSupport/CriticalSection.cpp b/src/OSSupport/CriticalSection.cpp
index 5248356c5..2e533676d 100644
--- a/src/OSSupport/CriticalSection.cpp
+++ b/src/OSSupport/CriticalSection.cpp
@@ -23,7 +23,7 @@ cCriticalSection::cCriticalSection()
void cCriticalSection::Lock()
{
m_Mutex.lock();
-
+
#ifdef _DEBUG
m_IsLocked += 1;
m_OwningThreadID = std::this_thread::get_id();
@@ -40,7 +40,7 @@ void cCriticalSection::Unlock()
ASSERT(m_IsLocked > 0);
m_IsLocked -= 1;
#endif // _DEBUG
-
+
m_Mutex.unlock();
}
diff --git a/src/OSSupport/CriticalSection.h b/src/OSSupport/CriticalSection.h
index 236a7d203..6ea18051a 100644
--- a/src/OSSupport/CriticalSection.h
+++ b/src/OSSupport/CriticalSection.h
@@ -12,7 +12,7 @@ class cCriticalSection
public:
void Lock(void);
void Unlock(void);
-
+
// IsLocked / IsLockedByCurrentThread are only used in ASSERT statements, but because of the changes with ASSERT they must always be defined
// The fake versions (in Release) will not effect the program in any way
#ifdef _DEBUG
@@ -23,14 +23,14 @@ public:
bool IsLocked(void) { return false; }
bool IsLockedByCurrentThread(void) { return false; }
#endif // _DEBUG
-
+
private:
#ifdef _DEBUG
int m_IsLocked; // Number of times this CS is locked
std::thread::id m_OwningThreadID;
#endif // _DEBUG
-
+
std::recursive_mutex m_Mutex;
} ALIGN_8;
@@ -46,12 +46,12 @@ class cCSLock
// In Windows, it is an error to call cCriticalSection::Unlock() multiple times if the lock is not held,
// therefore we need to check this value whether we are locked or not.
bool m_IsLocked;
-
+
public:
cCSLock(cCriticalSection * a_CS);
cCSLock(cCriticalSection & a_CS);
~cCSLock();
-
+
// Temporarily unlock or re-lock:
void Lock(void);
void Unlock(void);
@@ -71,7 +71,7 @@ class cCSUnlock
public:
cCSUnlock(cCSLock & a_Lock);
~cCSUnlock();
-
+
private:
DISALLOW_COPY_AND_ASSIGN(cCSUnlock);
} ;
diff --git a/src/OSSupport/Errors.cpp b/src/OSSupport/Errors.cpp
index ce2e2acb0..a05650111 100644
--- a/src/OSSupport/Errors.cpp
+++ b/src/OSSupport/Errors.cpp
@@ -17,37 +17,37 @@ AString GetOSErrorString( int a_ErrNo)
Out.erase(Out.length() - 2);
}
return Out;
-
+
#else // _WIN32
-
+
// According to http://linux.die.net/man/3/strerror_r there are two versions of strerror_r():
-
+
#if defined(__GLIBC__) && defined( _GNU_SOURCE) && !defined(ANDROID_NDK) // GNU version of strerror_r()
-
+
char * res = strerror_r( errno, buffer, ARRAYCOUNT(buffer));
if (res != nullptr)
{
Printf(Out, "%d: %s", a_ErrNo, res);
return Out;
}
-
+
#else // XSI version of strerror_r():
-
+
int res = strerror_r( errno, buffer, ARRAYCOUNT(buffer));
if (res == 0)
{
Printf(Out, "%d: %s", a_ErrNo, buffer);
return Out;
}
-
+
#endif // strerror_r() version
-
+
else
{
Printf(Out, "Error %d while getting error string for error #%d!", errno, a_ErrNo);
return Out;
}
-
+
#endif // else _WIN32
}
diff --git a/src/OSSupport/Event.h b/src/OSSupport/Event.h
index 067a2207c..94f062123 100644
--- a/src/OSSupport/Event.h
+++ b/src/OSSupport/Event.h
@@ -37,7 +37,7 @@ public:
/** Waits for the event until either it is signalled, or the (relative) timeout is passed.
Returns true if the event was signalled, false if the timeout was hit or there was an error. */
bool Wait(unsigned a_TimeoutMSec);
-
+
private:
/** Used for checking for spurious wakeups. */
diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp
index d99892aae..b4e4c3f6f 100644
--- a/src/OSSupport/File.cpp
+++ b/src/OSSupport/File.cpp
@@ -50,12 +50,12 @@ cFile::~cFile()
bool cFile::Open(const AString & iFileName, eMode iMode)
{
ASSERT(!IsOpen()); // You should close the file before opening another one
-
+
if (IsOpen())
{
Close();
}
-
+
const char * Mode = nullptr;
switch (iMode)
{
@@ -125,13 +125,13 @@ bool cFile::IsOpen(void) const
bool cFile::IsEOF(void) const
{
ASSERT(IsOpen());
-
+
if (!IsOpen())
{
// Unopened files behave as at EOF
return true;
}
-
+
return (feof(m_File) != 0);
}
@@ -142,12 +142,12 @@ bool cFile::IsEOF(void) const
int cFile::Read (void * a_Buffer, size_t a_NumBytes)
{
ASSERT(IsOpen());
-
+
if (!IsOpen())
{
return -1;
}
-
+
return static_cast<int>(fread(a_Buffer, 1, a_NumBytes, m_File)); // fread() returns the portion of Count parameter actually read, so we need to send a_a_NumBytes as Count
}
@@ -158,7 +158,7 @@ int cFile::Read (void * a_Buffer, size_t a_NumBytes)
AString cFile::Read(size_t a_NumBytes)
{
ASSERT(IsOpen());
-
+
if (!IsOpen())
{
return AString();
@@ -179,7 +179,7 @@ AString cFile::Read(size_t a_NumBytes)
int cFile::Write(const void * a_Buffer, size_t a_NumBytes)
{
ASSERT(IsOpen());
-
+
if (!IsOpen())
{
return -1;
@@ -196,12 +196,12 @@ int cFile::Write(const void * a_Buffer, size_t a_NumBytes)
long cFile::Seek (int iPosition)
{
ASSERT(IsOpen());
-
+
if (!IsOpen())
{
return -1;
}
-
+
if (fseek(m_File, iPosition, SEEK_SET) != 0)
{
return -1;
@@ -217,12 +217,12 @@ long cFile::Seek (int iPosition)
long cFile::Tell (void) const
{
ASSERT(IsOpen());
-
+
if (!IsOpen())
{
return -1;
}
-
+
return ftell(m_File);
}
@@ -233,12 +233,12 @@ long cFile::Tell (void) const
long cFile::GetSize(void) const
{
ASSERT(IsOpen());
-
+
if (!IsOpen())
{
return -1;
}
-
+
long CurPos = Tell();
if (CurPos < 0)
{
@@ -263,12 +263,12 @@ long cFile::GetSize(void) const
int cFile::ReadRestOfFile(AString & a_Contents)
{
ASSERT(IsOpen());
-
+
if (!IsOpen())
{
return -1;
}
-
+
long TotalSize = GetSize();
if (TotalSize < 0)
{
@@ -282,7 +282,7 @@ int cFile::ReadRestOfFile(AString & a_Contents)
}
auto DataSize = static_cast<size_t>(TotalSize - Position);
-
+
// HACK: This depends on the internal knowledge that AString's data() function returns the internal buffer directly
a_Contents.assign(DataSize, '\0');
return Read(reinterpret_cast<void *>(const_cast<char *>(a_Contents.data())), DataSize);
@@ -502,7 +502,7 @@ bool cFile::CreateFolderRecursive(const AString & a_FolderPath)
AStringVector cFile::GetFolderContents(const AString & a_Folder)
{
AStringVector AllFiles;
-
+
#ifdef _WIN32
// If the folder name doesn't contain the terminating slash / backslash, add it:
@@ -515,7 +515,7 @@ AStringVector cFile::GetFolderContents(const AString & a_Folder)
{
FileFilter.push_back('\\');
}
-
+
// Find all files / folders:
FileFilter.append("*.*");
HANDLE hFind;
@@ -528,7 +528,7 @@ AStringVector cFile::GetFolderContents(const AString & a_Folder)
} while (FindNextFileA(hFind, &FindFileData));
FindClose(hFind);
}
-
+
#else // _WIN32
DIR * dp;
@@ -550,7 +550,7 @@ AStringVector cFile::GetFolderContents(const AString & a_Folder)
}
closedir(dp);
}
-
+
#endif // else _WIN32
return AllFiles;
diff --git a/src/OSSupport/File.h b/src/OSSupport/File.h
index aab86811d..28485d9f8 100644
--- a/src/OSSupport/File.h
+++ b/src/OSSupport/File.h
@@ -39,13 +39,13 @@ class cFile
public:
// tolua_end
-
+
#ifdef _WIN32
static const char PathSeparator = '\\';
#else
static const char PathSeparator = '/';
#endif
-
+
/** The mode in which to open the file */
enum eMode
{
@@ -54,45 +54,45 @@ public:
fmReadWrite, // Read / write. If the file already exists, it will be left intact; writing will overwrite the data from the beginning
fmAppend // Write-only. If the file already exists cursor will be moved to the end of the file
} ;
-
+
/** Simple constructor - creates an unopened file object, use Open() to open / create a real file */
cFile(void);
-
+
/** Constructs and opens / creates the file specified, use IsOpen() to check for success */
cFile(const AString & iFileName, eMode iMode);
-
+
/** Auto-closes the file, if open */
~cFile();
-
+
bool Open(const AString & iFileName, eMode iMode);
void Close(void);
bool IsOpen(void) const;
bool IsEOF(void) const;
-
+
/** Reads up to a_NumBytes bytes into a_Buffer, returns the number of bytes actually read, or -1 on failure; asserts if not open */
int Read(void * a_Buffer, size_t a_NumBytes);
-
+
/** Reads up to a_NumBytes bytes, returns the bytes actually read, or empty string on failure; asserts if not open */
AString Read(size_t a_NumBytes);
/** Writes up to a_NumBytes bytes from a_Buffer, returns the number of bytes actually written, or -1 on failure; asserts if not open */
int Write(const void * a_Buffer, size_t a_NumBytes);
-
+
/** Seeks to iPosition bytes from file start, returns old position or -1 for failure; asserts if not open */
long Seek (int iPosition);
-
+
/** Returns the current position (bytes from file start) or -1 for failure; asserts if not open */
long Tell (void) const;
-
+
/** Returns the size of file, in bytes, or -1 for failure; asserts if not open */
long GetSize(void) const;
-
+
/** Reads the file from current position till EOF into an AString; returns the number of bytes read or -1 for error */
int ReadRestOfFile(AString & a_Contents);
-
+
/** Returns true if the file specified exists */
static bool Exists(const AString & a_FileName); // Exported in ManualBindings.cpp
-
+
/** Deletes a file or a folder, returns true if successful.
Prefer to use DeleteFile or DeleteFolder, since those don't have the penalty of checking whether a_Path is a folder. */
static bool Delete(const AString & a_Path); // Exported in ManualBindings.cpp
@@ -100,7 +100,7 @@ public:
/** Deletes a file, returns true if successful.
Returns false if a_FileName points to a folder. */
static bool DeleteFile(const AString & a_FileName); // Exported in ManualBindings.cpp
-
+
/** Deletes a folder, returns true if successful.
Returns false if a_FolderName points to a file. */
static bool DeleteFolder(const AString & a_FolderName); // Exported in ManualBindings.cpp
@@ -109,23 +109,23 @@ public:
The specified folder itself stays intact.
Returns true on success, false on failure. */
static bool DeleteFolderContents(const AString & a_FolderName); // Exported in ManualBindings.cpp
-
+
/** Renames a file or folder, returns true if successful. May fail if dest already exists (libc-dependant)! */
static bool Rename(const AString & a_OrigPath, const AString & a_NewPath); // Exported in ManualBindings.cpp
-
+
/** Copies a file, returns true if successful.
Overwrites the dest file if it already exists. */
static bool Copy(const AString & a_SrcFileName, const AString & a_DstFileName); // Exported in ManualBindings.cpp
-
+
/** Returns true if the specified path is a folder */
static bool IsFolder(const AString & a_Path); // Exported in ManualBindings.cpp
-
+
/** Returns true if the specified path is a regular file */
static bool IsFile(const AString & a_Path); // Exported in ManualBindings.cpp
-
+
/** Returns the size of the file, or a negative number on error */
static long GetSize(const AString & a_FileName); // Exported in ManualBindings.cpp
-
+
/** Creates a new folder with the specified name. Returns true if successful. Path may be relative or absolute */
static bool CreateFolder(const AString & a_FolderPath); // Exported in ManualBindings.cpp
@@ -133,7 +133,7 @@ public:
Returns true if the folder exists at the end of the operation (either created, or already existed).
Supports only paths that use the path separator used by the current platform (MSVC CRT supports slashes for file paths, too, but this function doesn't) */
static bool CreateFolderRecursive(const AString & a_FolderPath); // Exported in ManualBindings.cpp
-
+
/** Returns the entire contents of the specified file as a string. Returns empty string on error. */
static AString ReadWholeFile(const AString & a_FileName); // Exported in ManualBindings.cpp
@@ -157,15 +157,15 @@ public:
static AString GetExecutableExt(void);
// tolua_end
-
+
/** Returns the list of all items in the specified folder (files, folders, nix pipes, whatever's there). */
static AStringVector GetFolderContents(const AString & a_Folder); // Exported in ManualBindings.cpp
int Printf(const char * a_Fmt, ...) FORMATSTRING(2, 3);
-
+
/** Flushes all the bufferef output into the file (only when writing) */
void Flush(void);
-
+
private:
FILE * m_File;
} ; // tolua_export
diff --git a/src/OSSupport/GZipFile.cpp b/src/OSSupport/GZipFile.cpp
index 2ddc260e5..e83d42583 100644
--- a/src/OSSupport/GZipFile.cpp
+++ b/src/OSSupport/GZipFile.cpp
@@ -64,13 +64,13 @@ int cGZipFile::ReadRestOfFile(AString & a_Contents)
ASSERT(!"No file has been opened");
return -1;
}
-
+
if (m_Mode != fmRead)
{
ASSERT(!"Bad file mode, cannot read");
return -1;
}
-
+
// Since the gzip format doesn't really support getting the uncompressed length, we need to read incrementally. Yuck!
int NumBytesRead = 0;
int TotalBytes = 0;
diff --git a/src/OSSupport/GZipFile.h b/src/OSSupport/GZipFile.h
index d1728fd8e..00a2fd717 100644
--- a/src/OSSupport/GZipFile.h
+++ b/src/OSSupport/GZipFile.h
@@ -23,24 +23,24 @@ public:
fmRead, // Read-only. If the file doesn't exist, object will not be valid
fmWrite, // Write-only. If the file already exists, it will be overwritten
} ;
-
+
cGZipFile(void);
~cGZipFile();
-
+
/** Opens the file. Returns true if successful. Fails if a file has already been opened through this object. */
bool Open(const AString & a_FileName, eMode a_Mode);
-
+
/** Closes the file, flushing all buffers. This object may be then reused for a different file and / or mode */
void Close(void);
-
+
/** Reads the rest of the file and decompresses it into a_Contents. Returns the number of decompressed bytes, <0 for error */
int ReadRestOfFile(AString & a_Contents);
-
+
/** Writes a_Contents into file, compressing it along the way. Returns true if successful. Multiple writes are supported. */
bool Write(const AString & a_Contents) { return Write(a_Contents.data(), static_cast<int>(a_Contents.size())); }
-
+
bool Write(const char * a_Data, int a_Size);
-
+
protected:
gzFile m_File;
eMode m_Mode;
diff --git a/src/OSSupport/IsThread.h b/src/OSSupport/IsThread.h
index 0c28f5623..85f437267 100644
--- a/src/OSSupport/IsThread.h
+++ b/src/OSSupport/IsThread.h
@@ -48,7 +48,7 @@ public:
/** Returns true if the thread calling this function is the thread contained within this object. */
bool IsCurrentThread(void) const { return std::this_thread::get_id() == m_Thread.get_id(); }
-
+
private:
/** The name of the thread, used to aid debugging in IDEs which support named threads */
diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h
index 00d21c49b..d5a4bd443 100644
--- a/src/OSSupport/Queue.h
+++ b/src/OSSupport/Queue.h
@@ -26,7 +26,7 @@ public:
/** Called when an Item is deleted from the queue without being returned */
static void Delete(T) {}
-
+
/** Called when an Item is inserted with EnqueueItemIfNotPresent and there is another equal value already inserted */
static void Combine(T & a_existing, const T & a_new)
{
@@ -44,10 +44,10 @@ class cQueue
{
// The actual storage type for the queue
typedef typename std::list<ItemType> QueueType;
-
+
// Make iterator an alias for the QueueType's iterator
typedef typename QueueType::iterator iterator;
-
+
public:
cQueue() {}
~cQueue() {}
@@ -188,13 +188,13 @@ public:
private:
/** The contents of the queue */
QueueType m_Contents;
-
+
/** Mutex that protects access to the queue contents */
cCriticalSection m_CS;
-
+
/** Event that is signalled when an item is added */
cEvent m_evtAdded;
-
+
/** Event that is signalled when an item is removed (both dequeued or erased) */
cEvent m_evtRemoved;
};
diff --git a/src/OSSupport/TCPLinkImpl.cpp b/src/OSSupport/TCPLinkImpl.cpp
index ae6ba04f1..b15b6282f 100644
--- a/src/OSSupport/TCPLinkImpl.cpp
+++ b/src/OSSupport/TCPLinkImpl.cpp
@@ -274,7 +274,7 @@ void cTCPLinkImpl::EventCallback(bufferevent * a_BufferEvent, short a_What, void
Self->m_Self.reset();
return;
}
-
+
// Unknown event, report it:
LOGWARNING("cTCPLinkImpl: Unhandled LibEvent event %d (0x%x)", a_What, a_What);
ASSERT(!"cTCPLinkImpl: Unhandled LibEvent event");