library: normalized the 'read_failed' guys across APIs
This patch will condense some logic in those functions associated with the file input operations. The changes will not, for the most part, alter any generated code. More significantly (though not very) was the change to two 'strtoul' calls. Since the returned 'endptr' value isn't exploited, when that parm is set to NULL, we can save one instruction on each side of such calls (wow). Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
3d0e7f3d03
commit
f4e9195149
@ -646,7 +646,7 @@ static int meminfo_read_failed (
|
||||
memset(&info->hist.new, 0, sizeof(struct meminfo_data));
|
||||
|
||||
if (-1 == info->meminfo_fd
|
||||
&& (info->meminfo_fd = open(MEMINFO_FILE, O_RDONLY)) == -1)
|
||||
&& (-1 == (info->meminfo_fd = open(MEMINFO_FILE, O_RDONLY))))
|
||||
return 1;
|
||||
|
||||
if (lseek(info->meminfo_fd, 0L, SEEK_SET) == -1)
|
||||
@ -672,8 +672,7 @@ static int meminfo_read_failed (
|
||||
static ENTRY e; // just to keep coverity off our backs (e.data)
|
||||
ENTRY *ep;
|
||||
|
||||
tail = strchr(head, ' ');
|
||||
if (!tail)
|
||||
if (!(tail = strchr(head, ' ')))
|
||||
break;
|
||||
*tail = '\0';
|
||||
valptr = NULL;
|
||||
@ -681,13 +680,11 @@ static int meminfo_read_failed (
|
||||
e.key = head;
|
||||
if (hsearch_r(e, FIND, &ep, &info->hashtab))
|
||||
valptr = ep->data;
|
||||
|
||||
head = tail+1;
|
||||
head = tail + 1;
|
||||
if (valptr)
|
||||
*valptr = strtoul(head, &tail, 10);
|
||||
*valptr = strtoul(head, NULL, 10);
|
||||
|
||||
tail = strchr(head, '\n');
|
||||
if (!tail)
|
||||
if (!(tail = strchr(head, '\n')))
|
||||
break;
|
||||
head = tail + 1;
|
||||
}
|
||||
|
@ -1170,7 +1170,7 @@ static int vmstat_read_failed (
|
||||
memset(&info->hist.new, 0, sizeof(struct vmstat_data));
|
||||
|
||||
if (-1 == info->vmstat_fd
|
||||
&& (info->vmstat_fd = open(VMSTAT_FILE, O_RDONLY)) == -1)
|
||||
&& (-1 == (info->vmstat_fd = open(VMSTAT_FILE, O_RDONLY))))
|
||||
return 1;
|
||||
|
||||
if (lseek(info->vmstat_fd, 0L, SEEK_SET) == -1)
|
||||
@ -1196,8 +1196,7 @@ static int vmstat_read_failed (
|
||||
static ENTRY e; // just to keep coverity off our backs (e.data)
|
||||
ENTRY *ep;
|
||||
|
||||
tail = strchr(head, ' ');
|
||||
if (!tail)
|
||||
if (!(tail = strchr(head, ' ')))
|
||||
break;
|
||||
*tail = '\0';
|
||||
valptr = NULL;
|
||||
@ -1205,13 +1204,11 @@ static int vmstat_read_failed (
|
||||
e.key = head;
|
||||
if (hsearch_r(e, FIND, &ep, &info->hashtab))
|
||||
valptr = ep->data;
|
||||
|
||||
head = tail + 1;
|
||||
if (valptr)
|
||||
*valptr = strtoul(head, &tail, 10);
|
||||
*valptr = strtoul(head, NULL, 10);
|
||||
|
||||
tail = strchr(head, '\n');
|
||||
if (!tail)
|
||||
if (!(tail = strchr(head, '\n')))
|
||||
break;
|
||||
head = tail + 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user