[SIGAR-116] check return value from read() in sigar_file2str()
This commit is contained in:
parent
b0fad8130c
commit
1a0db053ed
|
@ -836,18 +836,23 @@ SIGAR_DECLARE(int) sigar_rpc_ping(char *host,
|
||||||
|
|
||||||
int sigar_file2str(const char *fname, char *buffer, int buflen)
|
int sigar_file2str(const char *fname, char *buffer, int buflen)
|
||||||
{
|
{
|
||||||
int len;
|
int len, status;
|
||||||
int fd = open(fname, O_RDONLY);
|
int fd = open(fname, O_RDONLY);
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
return ENOENT;
|
return ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = read(fd, buffer, buflen);
|
if ((len = read(fd, buffer, buflen)) < 0) {
|
||||||
|
status = errno;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
status = SIGAR_OK;
|
||||||
buffer[len] = '\0';
|
buffer[len] = '\0';
|
||||||
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
return SIGAR_OK;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
Loading…
Reference in New Issue