summaryrefslogtreecommitdiff
path: root/lib/common
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common')
-rw-r--r--lib/common/BoxConfig-MSVC.h9
-rw-r--r--lib/common/BoxPlatform.h33
-rw-r--r--lib/common/BoxTime.cpp39
-rw-r--r--lib/common/DebugMemLeakFinder.cpp12
-rw-r--r--lib/common/ExcludeList.cpp8
-rw-r--r--lib/common/Logging.cpp14
-rw-r--r--lib/common/Logging.h26
-rw-r--r--lib/common/RateLimitingStream.h2
-rw-r--r--lib/common/Test.h16
-rw-r--r--lib/common/Timer.cpp24
-rw-r--r--lib/common/Timer.h1
-rw-r--r--lib/common/Utils.cpp27
12 files changed, 97 insertions, 114 deletions
diff --git a/lib/common/BoxConfig-MSVC.h b/lib/common/BoxConfig-MSVC.h
index 82ab4997..2ec2edd7 100644
--- a/lib/common/BoxConfig-MSVC.h
+++ b/lib/common/BoxConfig-MSVC.h
@@ -2,9 +2,6 @@
/* lib/common/BoxConfig.h.in. Generated from configure.ac by autoheader. */
/* Hacked by hand to work for MSVC by Chris Wilson */
-// using std::min/max
-#define NOMINMAX
-
/* Define to major version for BDB_VERSION */
/* #undef BDB_VERSION_MAJOR */
@@ -389,9 +386,6 @@
/* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */
-/* Define to `int' if <sys/types.h> doesn't define. */
-#define gid_t int
-
/* Define to `int' if <sys/types.h> does not define. */
/* #undef mode_t */
@@ -403,6 +397,3 @@
/* Define to `unsigned' if <sys/types.h> does not define. */
/* #undef size_t */
-
-/* Define to `int' if <sys/types.h> doesn't define. */
-#define uid_t int
diff --git a/lib/common/BoxPlatform.h b/lib/common/BoxPlatform.h
index 35ad7a2c..f7c74bfc 100644
--- a/lib/common/BoxPlatform.h
+++ b/lib/common/BoxPlatform.h
@@ -21,11 +21,13 @@
#define PLATFORM_DEV_NULL "/dev/null"
-#ifdef _MSC_VER
-#include "BoxConfig-MSVC.h"
-#define NEED_BOX_VERSION_H
+#if defined BOX_CMAKE
+# include "BoxConfig.cmake.h"
+#elif defined _MSC_VER
+# include "BoxConfig-MSVC.h"
+# define NEED_BOX_VERSION_H
#else
-#include "BoxConfig.h"
+# include "BoxConfig.h"
#endif
#ifdef WIN32
@@ -96,16 +98,19 @@
#endif
// Handle differing xattr APIs
-#ifdef HAVE_SYS_XATTR_H
- #if !defined(HAVE_LLISTXATTR) && defined(HAVE_LISTXATTR) && HAVE_DECL_XATTR_NOFOLLOW
- #define llistxattr(a,b,c) listxattr(a,b,c,XATTR_NOFOLLOW)
- #endif
- #if !defined(HAVE_LGETXATTR) && defined(HAVE_GETXATTR) && HAVE_DECL_XATTR_NOFOLLOW
- #define lgetxattr(a,b,c,d) getxattr(a,b,c,d,0,XATTR_NOFOLLOW)
- #endif
- #if !defined(HAVE_LSETXATTR) && defined(HAVE_SETXATTR) && HAVE_DECL_XATTR_NOFOLLOW
- #define lsetxattr(a,b,c,d,e) setxattr(a,b,c,d,0,(e)|XATTR_NOFOLLOW)
- #endif
+#if !defined(HAVE_LLISTXATTR) && defined(HAVE_LISTXATTR) && HAVE_DECL_XATTR_NOFOLLOW
+ #define llistxattr(a,b,c) listxattr(a,b,c,XATTR_NOFOLLOW)
+ #define HAVE_LLISTXATTR
+#endif
+
+#if !defined(HAVE_LGETXATTR) && defined(HAVE_GETXATTR) && HAVE_DECL_XATTR_NOFOLLOW
+ #define lgetxattr(a,b,c,d) getxattr(a,b,c,d,0,XATTR_NOFOLLOW)
+ #define HAVE_LGETXATTR
+#endif
+
+#if !defined(HAVE_LSETXATTR) && defined(HAVE_SETXATTR) && HAVE_DECL_XATTR_NOFOLLOW
+ #define lsetxattr(a,b,c,d,e) setxattr(a,b,c,d,0,(e)|XATTR_NOFOLLOW)
+ #define HAVE_LSETXATTR
#endif
#if !HAVE_DECL_INFTIM
diff --git a/lib/common/BoxTime.cpp b/lib/common/BoxTime.cpp
index 78269def..77daae6d 100644
--- a/lib/common/BoxTime.cpp
+++ b/lib/common/BoxTime.cpp
@@ -35,21 +35,30 @@
// --------------------------------------------------------------------------
box_time_t GetCurrentBoxTime()
{
- #ifdef HAVE_GETTIMEOFDAY
- struct timeval tv;
- if (gettimeofday(&tv, NULL) != 0)
- {
- BOX_LOG_SYS_ERROR("Failed to gettimeofday(), "
- "dropping precision");
- }
- else
- {
- box_time_t timeNow = (tv.tv_sec * MICRO_SEC_IN_SEC_LL)
- + tv.tv_usec;
- return timeNow;
- }
- #endif
-
+#ifdef HAVE_GETTIMEOFDAY
+ struct timeval tv;
+ if (gettimeofday(&tv, NULL) != 0)
+ {
+ BOX_LOG_SYS_ERROR("Failed to gettimeofday(), "
+ "dropping precision");
+ }
+ else
+ {
+ box_time_t time_now = (tv.tv_sec * MICRO_SEC_IN_SEC_LL) + tv.tv_usec;
+ return time_now;
+ }
+#elif WIN32
+ // There's no Win32 API function that returns the current time as a UNIX timestamp with
+ // sub-second precision. So we use time(0) and add the fractional part from
+ // GetSystemTime() in the hope that the difference between these two (if any) is a whole
+ // number of seconds.
+ box_time_t time_now = SecondsToBoxTime(time(0));
+ SYSTEMTIME system_time;
+ GetSystemTime(&system_time);
+ time_now += MilliSecondsToBoxTime(system_time.wMilliseconds);
+ return time_now;
+#endif
+
return SecondsToBoxTime(time(0));
}
diff --git a/lib/common/DebugMemLeakFinder.cpp b/lib/common/DebugMemLeakFinder.cpp
index 81e999c4..58a82c0e 100644
--- a/lib/common/DebugMemLeakFinder.cpp
+++ b/lib/common/DebugMemLeakFinder.cpp
@@ -15,15 +15,19 @@
#undef realloc
#undef free
-#ifdef HAVE_UNISTD_H
- #include <unistd.h>
-#endif
-
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
+#ifdef HAVE_PROCESS_H
+# include <process.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
#include <cstdlib> // for std::atexit
#include <map>
#include <set>
diff --git a/lib/common/ExcludeList.cpp b/lib/common/ExcludeList.cpp
index f101782a..3f9f69ee 100644
--- a/lib/common/ExcludeList.cpp
+++ b/lib/common/ExcludeList.cpp
@@ -10,9 +10,9 @@
#include "Box.h"
#ifdef HAVE_REGEX_SUPPORT
- #ifdef HAVE_PCREPOSIX_H
+ #if defined HAVE_PCREPOSIX_H
#include <pcreposix.h>
- #else
+ #elif defined HAVE_REGEX_H
#include <regex.h>
#endif
#define EXCLUDELIST_IMPLEMENTATION_REGEX_T_DEFINED
@@ -199,11 +199,9 @@ void ExcludeList::AddRegexEntries(const std::string &rEntries)
{
char buf[1024];
regerror(errcode, pregex, buf, sizeof(buf));
- BOX_LOG_CATEGORY(Log::ERROR,
- ConfigurationVerify::VERIFY_ERROR,
+ THROW_EXCEPTION_MESSAGE(CommonException, BadRegularExpression,
"Invalid regular expression: " <<
entry << ": " << buf);
- THROW_EXCEPTION(CommonException, BadRegularExpression)
}
// Store in list of regular expressions
diff --git a/lib/common/Logging.cpp b/lib/common/Logging.cpp
index a0d1ec8c..0928a4d4 100644
--- a/lib/common/Logging.cpp
+++ b/lib/common/Logging.cpp
@@ -13,19 +13,19 @@
#include <time.h>
#include <string.h> // for stderror
-// c.f. http://bugs.debian.org/512510
-#include <cstdio>
+#ifdef HAVE_PROCESS_H
+# include <process.h>
+#endif
#ifdef HAVE_SYSLOG_H
- #include <syslog.h>
+# include <syslog.h>
#endif
+
#ifdef HAVE_UNISTD_H
- #include <unistd.h>
-#endif
-#ifdef WIN32
- #include <process.h>
+# include <unistd.h>
#endif
+#include <cstdio>
#include <cstring>
#include <iomanip>
diff --git a/lib/common/Logging.h b/lib/common/Logging.h
index 01358617..3dc3e69c 100644
--- a/lib/common/Logging.h
+++ b/lib/common/Logging.h
@@ -295,6 +295,32 @@ class Console : public Logger
static void SetShowTimeMicros(bool enabled);
static void SetShowPID(bool enabled);
static bool GetShowTag() { return sShowTag; }
+
+ class SettingsGuard
+ {
+ private:
+ bool mShowTag;
+ bool mShowTime;
+ bool mShowTimeMicros;
+ bool mShowPID;
+ std::string mTag;
+ public:
+ SettingsGuard()
+ : mShowTag(Console::sShowTag),
+ mShowTime(Console::sShowTime),
+ mShowTimeMicros(Console::sShowTimeMicros),
+ mShowPID(Console::sShowPID),
+ mTag(Console::sTag)
+ { }
+ ~SettingsGuard()
+ {
+ Console::SetShowTag(mShowTag);
+ Console::SetShowTime(mShowTime);
+ Console::SetShowTimeMicros(mShowTimeMicros);
+ Console::SetShowPID(mShowPID);
+ Console::sTag = mTag;
+ }
+ };
};
// --------------------------------------------------------------------------
diff --git a/lib/common/RateLimitingStream.h b/lib/common/RateLimitingStream.h
index cd9d8271..818c90af 100644
--- a/lib/common/RateLimitingStream.h
+++ b/lib/common/RateLimitingStream.h
@@ -33,7 +33,7 @@ public:
virtual void Write(const void *pBuffer, int NBytes,
int Timeout = IOStream::TimeOutInfinite)
{
- Write(pBuffer, NBytes, Timeout);
+ mrSink.Write(pBuffer, NBytes, Timeout);
}
virtual pos_type BytesLeftToRead()
{
diff --git a/lib/common/Test.h b/lib/common/Test.h
index 36cd6a59..4b5cef61 100644
--- a/lib/common/Test.h
+++ b/lib/common/Test.h
@@ -243,12 +243,14 @@ void safe_sleep(int seconds);
std::auto_ptr<Configuration> load_config_file(const std::string& config_file,
const ConfigurationVerify& verify);
-#ifdef _MSC_VER
- // Our CMakeFiles compile tests to different executable filenames,
- // e.g. test_common.exe instead of _test.exe.
- #define TEST_EXECUTABLE BOX_MODULE ".exe"
-#else
- #define TEST_EXECUTABLE "./_test"
-#endif
+#ifndef TEST_EXECUTABLE
+# ifdef _MSC_VER
+ // Our CMakeFiles compile tests to different executable filenames,
+ // e.g. test_common.exe instead of _test.exe.
+ #define TEST_EXECUTABLE BOX_MODULE ".exe"
+# else
+ #define TEST_EXECUTABLE "./_test"
+# endif
+#endif // TEST_EXECUTABLE
#endif // TEST__H
diff --git a/lib/common/Timer.cpp b/lib/common/Timer.cpp
index 6ce84b7d..4f8c989e 100644
--- a/lib/common/Timer.cpp
+++ b/lib/common/Timer.cpp
@@ -123,26 +123,6 @@ void Timers::Cleanup(bool throw_exception_if_not_initialised)
// --------------------------------------------------------------------------
//
// Function
-// Name: static void Timers::AssertInitialised()
-// Purpose: Throw an assertion error if timers are not ready
-// NOW. It's a common mistake (for me) when writing
-// tests to forget to initialise timers first.
-// Created: 15/05/2014
-//
-// --------------------------------------------------------------------------
-
-void Timers::AssertInitialised()
-{
- if (!spTimers)
- {
- THROW_EXCEPTION(CommonException, TimersNotInitialised);
- }
- ASSERT(spTimers);
-}
-
-// --------------------------------------------------------------------------
-//
-// Function
// Name: static void Timers::Add(Timer&)
// Purpose: Add a new timer to the set, and reschedule next wakeup
// Created: 5/11/2006
@@ -151,7 +131,6 @@ void Timers::AssertInitialised()
void Timers::Add(Timer& rTimer)
{
ASSERT(spTimers);
- ASSERT(&rTimer);
BOX_TRACE(TIMER_ID_OF(rTimer) " added to global queue, rescheduling");
spTimers->push_back(&rTimer);
Reschedule();
@@ -168,8 +147,6 @@ void Timers::Add(Timer& rTimer)
// --------------------------------------------------------------------------
void Timers::Remove(Timer& rTimer)
{
- ASSERT(&rTimer);
-
if(!spTimers)
{
BOX_WARNING(TIMER_ID_OF(rTimer) " was still active after "
@@ -343,7 +320,6 @@ void Timers::Reschedule()
// --------------------------------------------------------------------------
void Timers::SignalHandler(int unused)
{
- // ASSERT(spTimers);
Timers::RequestReschedule();
}
diff --git a/lib/common/Timer.h b/lib/common/Timer.h
index 68592aaa..17233203 100644
--- a/lib/common/Timer.h
+++ b/lib/common/Timer.h
@@ -44,7 +44,6 @@ class Timers
public:
static void Init();
static void Cleanup(bool throw_exception_if_not_initialised = true);
- static void AssertInitialised();
static void Add (Timer& rTimer);
static void Remove(Timer& rTimer);
static void RequestReschedule();
diff --git a/lib/common/Utils.cpp b/lib/common/Utils.cpp
index 4325dd88..0915f29a 100644
--- a/lib/common/Utils.cpp
+++ b/lib/common/Utils.cpp
@@ -381,30 +381,3 @@ std::string FormatUsageLineStart(const std::string& rName,
return result.str();
}
-std::string BoxGetTemporaryDirectoryName()
-{
-#ifdef WIN32
- // http://msdn.microsoft.com/library/default.asp?
- // url=/library/en-us/fileio/fs/creating_and_using_a_temporary_file.asp
-
- DWORD dwRetVal;
- char lpPathBuffer[1024];
- DWORD dwBufSize = sizeof(lpPathBuffer);
-
- // Get the temp path.
- dwRetVal = GetTempPath(dwBufSize, // length of the buffer
- lpPathBuffer); // buffer for path
- if (dwRetVal > dwBufSize)
- {
- THROW_EXCEPTION(CommonException, TempDirPathTooLong)
- }
-
- return std::string(lpPathBuffer);
-#elif defined TEMP_DIRECTORY_NAME
- return std::string(TEMP_DIRECTORY_NAME);
-#else
- #error non-static temporary directory names not supported yet
-#endif
-}
-
-