file_utils: allow fd_to_buf() to fail for real

parent f43ed6a0
...@@ -455,12 +455,15 @@ int fd_to_buf(int fd, char **buf, size_t *length) ...@@ -455,12 +455,15 @@ int fd_to_buf(int fd, char **buf, size_t *length)
bytes_read = lxc_read_nointr(fd, chunk, sizeof(chunk)); bytes_read = lxc_read_nointr(fd, chunk, sizeof(chunk));
if (bytes_read < 0) if (bytes_read < 0)
return 0; return -errno;
if (!bytes_read) if (!bytes_read)
break; break;
copy = must_realloc(old, (*length + bytes_read) * sizeof(*old)); copy = realloc(old, (*length + bytes_read) * sizeof(*old));
if (!copy)
return ret_errno(ENOMEM);
memcpy(copy + *length, chunk, bytes_read); memcpy(copy + *length, chunk, bytes_read);
*length += bytes_read; *length += bytes_read;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment