Replace long with int64_t in exiv2app.hpp

This commit is contained in:
Kevin Backhouse
2022-05-22 19:59:11 +01:00
parent 2e0ab1a037
commit 1ceddb2962
7 changed files with 183 additions and 118 deletions
+11 -4
View File
@@ -1,19 +1,26 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "app_utils.hpp"
#include <climits>
#include <cstdlib>
#include <limits>
namespace Util {
bool strtol(const char* nptr, long& n) {
bool strtol(const char* nptr, int64_t& n) {
if (!nptr || *nptr == '\0')
return false;
char* endptr = nullptr;
long tmp = std::strtol(nptr, &endptr, 10);
long long tmp = std::strtoll(nptr, &endptr, 10);
if (*endptr != '\0')
return false;
if (tmp == LONG_MAX || tmp == LONG_MIN)
// strtoll returns LLONG_MAX or LLONG_MIN if an overflow occurs.
if (tmp == LLONG_MAX || tmp == LLONG_MIN)
return false;
n = tmp;
if (tmp < std::numeric_limits<int64_t>::min())
return false;
if (tmp > std::numeric_limits<int64_t>::max())
return false;
n = static_cast<int64_t>(tmp);
return true;
}