Skip to content

Commit

Permalink
Fix compilation errors specifically compiling for C++03
Browse files Browse the repository at this point in the history
  • Loading branch information
smtrfnv authored Apr 12, 2024
1 parent bb7740a commit fe4a079
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 49 deletions.
2 changes: 1 addition & 1 deletion groups/nts/ntsa/ntsa_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,7 @@ ntsa::Error DataUtilImpl::copyConstBuffer(bsl::streambuf* destination,
}

std::streamsize numBytesToCopy;
if (numBytesRemaining <= numBytesToCopyMax) {
if (numBytesRemaining <= static_cast<bsl::size_t>(numBytesToCopyMax)) {
numBytesToCopy = static_cast<std::streamsize>(numBytesRemaining);
}
else {
Expand Down
6 changes: 3 additions & 3 deletions groups/nts/ntsa/ntsa_localname.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ LocalName::LocalName()
{
bsl::memset(d_path, 0, k_MAX_PATH_LENGTH);
#if defined(BSLS_PLATFORM_OS_AIX)
BSLMF_ASSERT(k_MAX_PATH_LENGTH <= (sizeof(sockaddr_un::sun_path) - 1));
BSLMF_ASSERT(k_MAX_PATH_LENGTH <= (sizeof(sockaddr_un().sun_path) - 1));
#else
BSLMF_ASSERT(k_MAX_PATH_LENGTH == (sizeof(sockaddr_un::sun_path) - 1));
BSLMF_ASSERT(k_MAX_PATH_LENGTH == (sizeof(sockaddr_un().sun_path) - 1));
#endif
}

Expand Down Expand Up @@ -86,7 +86,7 @@ ntsa::Error LocalName::setAbstract()
{
#if defined(BSLS_PLATFORM_OS_LINUX)
if (d_size == k_MAX_PATH_LENGTH) {
return ntsa::Error(ntsa::Error::Code::e_LIMIT);
return ntsa::Error(ntsa::Error::e_LIMIT);
}
d_abstract = true;
return ntsa::Error();
Expand Down
4 changes: 2 additions & 2 deletions groups/nts/ntsa/ntsa_localname.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ NTSCFG_TEST_CASE(4)
ntsa::LocalName localName;
NTSCFG_TEST_OK(localName.setAbstract());
NTSCFG_TEST_ERROR(localName.setValue(ss.str()),
ntsa::Error::Code::e_LIMIT);
ntsa::Error::e_LIMIT);
}
{
ntsa::LocalName localName;
Expand All @@ -262,7 +262,7 @@ NTSCFG_TEST_CASE(4)
ntsa::LocalName localName;
NTSCFG_TEST_OK(localName.setValue(ss.str()));
NTSCFG_TEST_ERROR(localName.setAbstract(),
ntsa::Error::Code::e_LIMIT);
ntsa::Error::e_LIMIT);
}
#endif

Expand Down
85 changes: 42 additions & 43 deletions groups/nts/ntsu/ntsu_timestamputil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
#include <bslmf_assert.h>
#include <bsls_platform.h>
#include <bsl_cstdint.h>
#include <bsl_sstream.h>
#include <bsl_iostream.h>
#include <bsl_iomanip.h>
#include <bsl_iostream.h>
#include <bsl_sstream.h>

// clang-format off
#if defined(BSLS_PLATFORM_OS_LINUX)
Expand All @@ -35,16 +35,15 @@

#if defined(BSLS_PLATFORM_OS_LINUX)

#define NTSU_TIMESTAMP_UTIL_LINUX_VERSION(major, minor, patch) \
static_cast<bsl::size_t>( \
KERNEL_VERSION( \
static_cast<bsl::size_t>(versionMajor), \
static_cast<bsl::size_t>(versionMinor), \
static_cast<bsl::size_t>(versionPatch)))
#define NTSU_TIMESTAMP_UTIL_LINUX_VERSION(major, minor, patch) \
static_cast<bsl::size_t>( \
KERNEL_VERSION(static_cast<bsl::size_t>(versionMajor), \
static_cast<bsl::size_t>(versionMinor), \
static_cast<bsl::size_t>(versionPatch)))

#define NTSU_TIMESTAMP_UTIL_LINUX_VERSION_GE(version, major, minor, patch) \
(static_cast<bsl::size_t>(version)) >= \
(NTSU_TIMESTAMP_UTIL_LINUX_VERSION(major, minor, patch))
#define NTSU_TIMESTAMP_UTIL_LINUX_VERSION_GE(version, major, minor, patch) \
(static_cast<bsl::size_t>(version)) >= \
(NTSU_TIMESTAMP_UTIL_LINUX_VERSION(major, minor, patch))

#endif

Expand Down Expand Up @@ -90,7 +89,7 @@ static TimestampOtionSupport s_timestampOptionSupport[] = {

#endif

} // close unnamed namespace
} // close unnamed namespace

#if defined(BSLS_PLATFORM_OS_LINUX)

Expand Down Expand Up @@ -136,48 +135,46 @@ BSLMF_ASSERT(TimestampUtil::e_SOF_TIMESTAMPING_OPT_TSONLY ==
#endif

BSLMF_ASSERT(sizeof(TimestampUtil::Timespec) == sizeof(timespec));
BSLMF_ASSERT(sizeof(TimestampUtil::Timespec::tv_sec) ==
sizeof(timespec::tv_sec));
BSLMF_ASSERT(sizeof(TimestampUtil::Timespec::tv_nsec) ==
sizeof(timespec::tv_nsec));
BSLMF_ASSERT(sizeof(TimestampUtil::Timespec().tv_sec) ==
sizeof(timespec().tv_sec));
BSLMF_ASSERT(sizeof(TimestampUtil::Timespec().tv_nsec) ==
sizeof(timespec().tv_nsec));

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)

BSLMF_ASSERT(sizeof(TimestampUtil::ScmTimestamping) ==
sizeof(scm_timestamping));
BSLMF_ASSERT(sizeof(TimestampUtil::ScmTimestamping::softwareTs) ==
sizeof(scm_timestamping::ts[0]));
BSLMF_ASSERT((sizeof(TimestampUtil::ScmTimestamping::hardwareTs) +
sizeof(TimestampUtil::ScmTimestamping::deprecated) +
sizeof(TimestampUtil::ScmTimestamping::hardwareTs)) ==
sizeof(scm_timestamping::ts[0]) * 3);
BSLMF_ASSERT(sizeof(TimestampUtil::ScmTimestamping().softwareTs) ==
sizeof(scm_timestamping().ts[0]));
BSLMF_ASSERT((sizeof(TimestampUtil::ScmTimestamping().hardwareTs) +
sizeof(TimestampUtil::ScmTimestamping().deprecated) +
sizeof(TimestampUtil::ScmTimestamping().hardwareTs)) ==
sizeof(scm_timestamping().ts[0]) * 3);

#endif

#endif

bool TimestampUtil::supportsOption(int option,
int versionMajor,
int versionMinor,
bool TimestampUtil::supportsOption(int option,
int versionMajor,
int versionMinor,
int versionPatch)
{
#if defined(BSLS_PLATFORM_OS_LINUX)

bsl::size_t version =
NTSU_TIMESTAMP_UTIL_LINUX_VERSION(
versionMajor,
versionMinor,
versionPatch);
bsl::size_t version = NTSU_TIMESTAMP_UTIL_LINUX_VERSION(versionMajor,
versionMinor,
versionPatch);

const bsl::size_t count =
const bsl::size_t count =
sizeof(s_timestampOptionSupport) / sizeof(s_timestampOptionSupport[0]);

for (bsl::size_t i = 0; i < count; ++i) {
if ((option & s_timestampOptionSupport[i].option) != 0) {
return NTSU_TIMESTAMP_UTIL_LINUX_VERSION_GE(
version,
s_timestampOptionSupport[i].versionMajor,
s_timestampOptionSupport[i].versionMinor,
version,
s_timestampOptionSupport[i].versionMajor,
s_timestampOptionSupport[i].versionMinor,
s_timestampOptionSupport[i].versionPatch);
}
}
Expand Down Expand Up @@ -205,8 +202,10 @@ int TimestampUtil::removeUnsupported(int options)
int versionPatch = 0;
int build = 0;

ntsscm::Version::systemVersion(
&versionMajor, &versionMinor, &versionPatch, &build);
ntsscm::Version::systemVersion(&versionMajor,
&versionMinor,
&versionPatch,
&build);

NTSCFG_WARNING_UNUSED(build);

Expand All @@ -219,11 +218,11 @@ int TimestampUtil::removeUnsupported(int options)
int flag = (1 << i);

if ((options & flag) != 0) {
const bool supportsOption = ntsu::TimestampUtil::supportsOption(
flag,
versionMajor,
versionMinor,
versionPatch);
const bool supportsOption =
ntsu::TimestampUtil::supportsOption(flag,
versionMajor,
versionMinor,
versionPatch);

if (!supportsOption) {
result &= ~flag;
Expand Down Expand Up @@ -255,12 +254,12 @@ bsl::string TimestampUtil::describeDelay(const bsls::TimeInterval& duration)
ss << duration.nanoseconds() / 1000 / 1000 << "ms";
}
else {
ss << bsl::fixed << bsl::setprecision(2)
ss << bsl::fixed << bsl::setprecision(2)
<< duration.totalSecondsAsDouble() << "s";
}
}
else {
ss << bsl::fixed << bsl::setprecision(2)
ss << bsl::fixed << bsl::setprecision(2)
<< duration.totalSecondsAsDouble() << "s";
}

Expand Down

0 comments on commit fe4a079

Please sign in to comment.