BatteryService(jni): properly handle read's return value

Change-Id: I10f5cf3728424e7f5a0c1b460049102fd00a6246
Signed-off-by: Dima Zavin <dima@android.com>
This commit is contained in:
Dima Zavin
2011-10-28 18:05:47 -07:00
parent fe9a2a5471
commit 98e044a609

View File

@@ -141,10 +141,10 @@ static int readFromFile(const char* path, char* buf, size_t size)
return -1;
}
size_t count = read(fd, buf, size);
ssize_t count = read(fd, buf, size);
if (count > 0) {
count = (count < size) ? count : size - 1;
while (count > 0 && buf[count-1] == '\n') count--;
while (count > 0 && buf[count-1] == '\n')
count--;
buf[count] = '\0';
} else {
buf[0] = '\0';