summaryrefslogtreecommitdiff
path: root/lib/common
diff options
context:
space:
mode:
authorReinhard Tartler <siretart@tauware.de>2020-05-10 15:21:30 -0400
committerReinhard Tartler <siretart@tauware.de>2020-05-10 15:21:30 -0400
commit657715ed754d69235aac62cd36f514f6dc65aab8 (patch)
tree96e6f410510f5d009de950fee644ba32ae79d593 /lib/common
parent6017757bc079f4446aa77bc5c0855c52741280f4 (diff)
New upstream version 0.13~~git20200326.g8e8b63c
Diffstat (limited to 'lib/common')
-rw-r--r--lib/common/BannerText.cpp14
-rw-r--r--lib/common/BannerText.h43
-rw-r--r--lib/common/Box.h16
-rw-r--r--lib/common/BoxPlatform.h4
-rw-r--r--lib/common/InvisibleTempFileStream.cpp2
-rw-r--r--lib/common/MainHelper.h10
-rw-r--r--lib/common/NamedLock.cpp4
-rw-r--r--lib/common/Test.cpp4
8 files changed, 80 insertions, 17 deletions
diff --git a/lib/common/BannerText.cpp b/lib/common/BannerText.cpp
new file mode 100644
index 00000000..9ec2c0d7
--- /dev/null
+++ b/lib/common/BannerText.cpp
@@ -0,0 +1,14 @@
+// --------------------------------------------------------------------------
+//
+// File
+// Name: BannerText.cpp
+// Purpose: Banner text for daemons and utilities
+// Created: 2018-08-16
+//
+// --------------------------------------------------------------------------
+
+#include "Box.h"
+
+#include "BannerText.h"
+
+#pragma message("Build signature: " BOX_BUILD_SIGNATURE)
diff --git a/lib/common/BannerText.h b/lib/common/BannerText.h
index 9ca0c11c..a2e412a8 100644
--- a/lib/common/BannerText.h
+++ b/lib/common/BannerText.h
@@ -14,9 +14,48 @@
# include "BoxVersion.h"
#endif
+// Already included by BoxPlatform.h:
+#include <stdint.h>
+
+// Yes, you need two function macros to stringify an expanded macro value.
+// https://stackoverflow.com/questions/5459868/concatenate-int-to-string-using-c-preprocessor
+#define BOX_STRINGIFY_HELPER(x) #x
+#define BOX_STRINGIFY(x) BOX_STRINGIFY_HELPER(x)
+
+// How to identify a 64-bit build: https://stackoverflow.com/a/687902/648162
+#if UINTPTR_MAX == (4294967295U)
+# define BOX_BUILD_BITS 32
+#elif UINTPTR_MAX == (18446744073709551615UL)
+# define BOX_BUILD_BITS 64
+#else
+# pragma message ("UINTPTR_MAX = " BOX_STRINGIFY(UINTPTR_MAX))
+# error Unknown architecture pointer size
+#endif
+
+#ifdef BOX_RELEASE_BUILD
+# define BOX_BUILD_TYPE Release
+#else
+# define BOX_BUILD_TYPE Debug
+#endif
+
+#define STRINGIFY1(x) #x
+#define STRINGIFY2(x) STRINGIFY1(x)
+#ifdef _MSC_VER
+# define BOX_COMPILER "MSVC " STRINGIFY2(_MSC_VER)
+#elif defined __GNUC__
+# define BOX_COMPILER "GCC " __VERSION__
+#elif defined __VERSION__
+// It might be an integer, not a string!
+# define BOX_COMPILER "Unknown " BOX_STRINGIFY(__VERSION__)
+#else
+# define BOX_COMPILER "Unknown"
+#endif
+
+#define BOX_BUILD_SIGNATURE BOX_COMPILER " " BOX_STRINGIFY(BOX_BUILD_BITS) "bit " BOX_STRINGIFY(BOX_BUILD_TYPE)
+
#define BANNER_TEXT(UtilityName) \
- "Box " UtilityName " v" BOX_VERSION ", (c) Ben Summers and " \
- "contributors 2003-2014"
+ "Box Backup " UtilityName " v" BOX_VERSION "\n" \
+ "(c) Ben Summers and contributors 2003-2020. Build type: " BOX_BUILD_SIGNATURE
#endif // BANNERTEXT__H
diff --git a/lib/common/Box.h b/lib/common/Box.h
index 8ce2a625..5f629790 100644
--- a/lib/common/Box.h
+++ b/lib/common/Box.h
@@ -39,7 +39,7 @@
#include "CommonException.h"
#include "Logging.h"
-#ifndef BOX_RELEASE_BUILD
+#ifndef BOX_RELEASE_BUILD // this is a debug build:
extern bool AssertFailuresToSyslog;
#define ASSERT_FAILS_TO_SYSLOG_ON {AssertFailuresToSyslog = true;}
void BoxDebugAssertFailed(const char *cond, const char *file, int line);
@@ -70,7 +70,7 @@
// Exception names
#define EXCEPTION_CODENAMES_EXTENDED
-#else
+#else // this is a release build:
#define ASSERT_FAILS_TO_SYSLOG_ON
#define ASSERT(cond)
@@ -80,19 +80,19 @@
// Box Backup builds release get extra information for exception logging
#define EXCEPTION_CODENAMES_EXTENDED
#define EXCEPTION_CODENAMES_EXTENDED_WITH_DESCRIPTION
+
+ #ifdef BOX_MEMORY_LEAK_TESTING
+ #error BOX_MEMORY_LEAK_TESTING should not already be defined in release builds!
+ #endif
#endif
-#if defined DEBUG_LEAKS
+#if defined DEBUG_LEAKS // optionally enable memory leak debugging even in release builds
#ifdef PLATFORM_DISABLE_MEM_LEAK_TESTING
#error Compiling with DEBUG_LEAKS enabled, but not supported on this platform
#else
#define BOX_MEMORY_LEAK_TESTING
#endif
-#elif defined BOX_RELEASE_BUILD
- #ifndef PLATFORM_DISABLE_MEM_LEAK_TESTING
- #define BOX_MEMORY_LEAK_TESTING
- #endif
-#endif // DEBUG_LEAKS || BOX_RELEASE_BUILD
+#endif // DEBUG_LEAKS
#ifdef BOX_MEMORY_LEAK_TESTING
// Memory leak testing
diff --git a/lib/common/BoxPlatform.h b/lib/common/BoxPlatform.h
index f7c74bfc..c86573f6 100644
--- a/lib/common/BoxPlatform.h
+++ b/lib/common/BoxPlatform.h
@@ -48,6 +48,10 @@
#include <sys/types.h>
#endif
+// Need to define this before including stdint.h to ensure access to UINTPTR_MAX in C99:
+// https://stackoverflow.com/questions/986426/what-do-stdc-limit-macros-and-stdc-constant-macros-mean
+#define __STDC_LIMIT_MACROS
+
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#else
diff --git a/lib/common/InvisibleTempFileStream.cpp b/lib/common/InvisibleTempFileStream.cpp
index 1a9d6d5a..d6d04489 100644
--- a/lib/common/InvisibleTempFileStream.cpp
+++ b/lib/common/InvisibleTempFileStream.cpp
@@ -31,7 +31,7 @@ InvisibleTempFileStream::InvisibleTempFileStream(const std::string& Filename,
#endif
{
#ifndef WIN32
- if(unlink(Filename.c_str()) != 0)
+ if(EMU_UNLINK(Filename.c_str()) != 0)
{
MEMLEAKFINDER_NOT_A_LEAK(this);
THROW_EXCEPTION(CommonException, OSFileOpenError)
diff --git a/lib/common/MainHelper.h b/lib/common/MainHelper.h
index 0303090e..f52607bf 100644
--- a/lib/common/MainHelper.h
+++ b/lib/common/MainHelper.h
@@ -16,13 +16,19 @@
# include "BoxVersion.h"
#endif
+#include "BannerText.h"
#include "BoxException.h"
#include "Logging.h"
#define MAINHELPER_START \
- if(argc == 2 && ::strcmp(argv[1], "--version") == 0) \
- { printf(BOX_VERSION "\n"); return 0; } \
+ /* need to init memleakfinder early because we already called MAINHELPER_SETUP_MEMORY_LEAK_EXIT_REPORT */ \
MEMLEAKFINDER_INIT \
+ if(argc == 2 && ::strcmp(argv[1], "--version") == 0) \
+ { \
+ printf("Version: " BOX_VERSION "\n"); \
+ printf("Build: " BOX_BUILD_SIGNATURE "\n"); \
+ return 0; \
+ } \
MEMLEAKFINDER_START \
try {
diff --git a/lib/common/NamedLock.cpp b/lib/common/NamedLock.cpp
index 8e672ff5..08d7c461 100644
--- a/lib/common/NamedLock.cpp
+++ b/lib/common/NamedLock.cpp
@@ -256,7 +256,7 @@ void NamedLock::ReleaseLock()
// Windows, and there we need to close the file before deleting it,
// otherwise the system won't let us delete it.
- if(::unlink(mFileName.c_str()) != 0)
+ if(EMU_UNLINK(mFileName.c_str()) != 0)
{
THROW_EMU_ERROR(
BOX_FILE_MESSAGE(mFileName, "Failed to delete lockfile"),
@@ -287,7 +287,7 @@ void NamedLock::ReleaseLock()
// On Windows we need to close the file before deleting it, otherwise
// the system won't let us delete it.
- if(::unlink(mFileName.c_str()) != 0)
+ if(EMU_UNLINK(mFileName.c_str()) != 0)
{
THROW_EMU_ERROR(
BOX_FILE_MESSAGE(mFileName, "Failed to delete lockfile"),
diff --git a/lib/common/Test.cpp b/lib/common/Test.cpp
index 3d1620a1..c6b28738 100644
--- a/lib/common/Test.cpp
+++ b/lib/common/Test.cpp
@@ -116,7 +116,7 @@ bool setUp(const char* function_name)
int filetype = ObjectExists(filepath);
if(filetype == ObjectExists_File)
{
- if(::unlink(filepath.c_str()) != 0)
+ if(EMU_UNLINK(filepath.c_str()) != 0)
{
TEST_FAIL_WITH_MESSAGE(BOX_SYS_ERROR_MESSAGE("Failed to delete "
"test fixture file: unlink(\"" << filepath << "\")"));
@@ -428,7 +428,7 @@ void TestRemoteProcessMemLeaksFunc(const char *filename,
}
// Delete it
- ::unlink(filename);
+ EMU_UNLINK(filename);
}
#endif
}