Skip to content

Commit

Permalink
Merge pull request ceph#12034 from wjwithagen/wip-wjw-freebsd-strtoll
Browse files Browse the repository at this point in the history
common/strtol.cc: Get error testing also to work on FreeBSD

Reviewed-by: Kefu Chai <[email protected]>
  • Loading branch information
tchaikov authored Nov 23, 2016
2 parents 2921d8d + ce47832 commit 6332a20
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/common/strtol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ long long strict_strtoll(const char *str, int base, std::string *err)
errno = 0; /* To distinguish success/failure after call (see man page) */
long long ret = strtoll(str, &endptr, base);

if (endptr == str) {
errStr = "Expected option value to be integer, got '";
errStr.append(str);
errStr.append("'");
*err = errStr;
return 0;
}
if ((errno == ERANGE && (ret == LLONG_MAX || ret == LLONG_MIN))
|| (errno != 0 && ret == 0)) {
errStr = "The option value '";
Expand All @@ -37,18 +44,11 @@ long long strict_strtoll(const char *str, int base, std::string *err)
*err = errStr;
return 0;
}
if (endptr == str) {
errStr = "Expected option value to be integer, got '";
errStr.append(str);
errStr.append("'");
*err = errStr;
return 0;
}
if (*endptr != '\0') {
errStr = "The option value '";
errStr.append(str);
errStr.append("'");
errStr.append(" seems to be invalid");
errStr.append(" contains invalid digits");
*err = errStr;
return 0;
}
Expand Down

0 comments on commit 6332a20

Please sign in to comment.