mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-24 21:05:40 +02:00
module/battery: convert asserts to real error checks
This commit is contained in:
parent
d81547066d
commit
30332670aa
1 changed files with 5 additions and 2 deletions
|
@ -109,8 +109,10 @@ readline_from_fd(int fd)
|
||||||
ssize_t sz = read(fd, buf, sizeof(buf) - 1);
|
ssize_t sz = read(fd, buf, sizeof(buf) - 1);
|
||||||
lseek(fd, 0, SEEK_SET);
|
lseek(fd, 0, SEEK_SET);
|
||||||
|
|
||||||
if (sz < 0)
|
if (sz < 0) {
|
||||||
|
LOG_WARN("failed to read from FD=%d", fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
buf[sz] = '\0';
|
buf[sz] = '\0';
|
||||||
for (ssize_t i = sz - 1; i >= 0 && buf[i] == '\n'; sz--)
|
for (ssize_t i = sz - 1; i >= 0 && buf[i] == '\n'; sz--)
|
||||||
|
@ -123,7 +125,8 @@ static long
|
||||||
readint_from_fd(int fd)
|
readint_from_fd(int fd)
|
||||||
{
|
{
|
||||||
const char *s = readline_from_fd(fd);
|
const char *s = readline_from_fd(fd);
|
||||||
assert(s != NULL);
|
if (s == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
long ret;
|
long ret;
|
||||||
int r = sscanf(s, "%ld", &ret);
|
int r = sscanf(s, "%ld", &ret);
|
||||||
|
|
Loading…
Add table
Reference in a new issue