virFileReadValueInt(const char *path, int *value)
{
char *str = NULL;
- char *endp = NULL;
if (!virFileExists(path))
return -2;
if (virFileReadAll(path, INT_STRLEN_BOUND(*value), &str) < 0)
return -1;
- if (virStrToLong_i(str, &endp, 10, value) < 0 ||
- (endp && !c_isspace(*endp))) {
+ virStringTrimOptionalNewline(str);
+
+ if (virStrToLong_i(str, NULL, 10, value) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid integer value '%s' in file '%s'"),
str, path);
virFileReadValueUint(const char *path, unsigned int *value)
{
char *str = NULL;
- char *endp = NULL;
if (!virFileExists(path))
return -2;
if (virFileReadAll(path, INT_STRLEN_BOUND(*value), &str) < 0)
return -1;
- if (virStrToLong_uip(str, &endp, 10, value) < 0 ||
- (endp && !c_isspace(*endp))) {
+ virStringTrimOptionalNewline(str);
+
+ if (virStrToLong_uip(str, NULL, 10, value)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid unsigned integer value '%s' in file '%s'"),
str, path);
{
char *buf = NULL;
int ret = -1;
- char *tmp = NULL;
if (!virFileExists(path))
return -2;
if (virFileReadAll(path, maxlen, &buf) < 0)
goto cleanup;
- /* trim optinoal newline at the end */
- tmp = buf + strlen(buf) - 1;
- if (*tmp == '\n')
- *tmp = '\0';
+ virStringTrimOptionalNewline(buf);
*value = virBitmapParseUnlimited(buf);
if (!*value)
tmp = str;
do {
if (virStrToLong_i(tmp, &tmp, 10, &ret) < 0 ||
- !strchr(",-\n", *tmp)) {
+ !strchr(",-", *tmp)) {
virReportError(VIR_ERR_NO_SUPPORT,
_("failed to parse %s"), str);
ret = -1;
goto cleanup;
}
- } while (*tmp++ != '\n');
+ } while (*tmp++ && *tmp);
ret++;
cleanup: