summaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2015-03-10 13:15:58 +0200
committerTimo Teräs <timo.teras@iki.fi>2015-03-10 13:15:58 +0200
commit255fd81d79c49f6e5dbdb0df371d8ec7de600917 (patch)
treea2e60a2e8048832c5b15afef86943505261c1ad4 /src/io.c
parent2a6896b2b4809849441756046ee7d8ad34abab34 (diff)
downloadapk-tools-255fd81d79c49f6e5dbdb0df371d8ec7de600917.tar.gz
apk-tools-255fd81d79c49f6e5dbdb0df371d8ec7de600917.tar.bz2
apk-tools-255fd81d79c49f6e5dbdb0df371d8ec7de600917.tar.xz
apk-tools-255fd81d79c49f6e5dbdb0df371d8ec7de600917.zip
rework error handling for write streams
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/io.c b/src/io.c
index f183c2a..6821c54 100644
--- a/src/io.c
+++ b/src/io.c
@@ -715,13 +715,12 @@ struct apk_ostream *apk_ostream_to_fd(int fd)
{
struct apk_fd_ostream *fos;
- if (fd < 0)
- return NULL;
+ if (fd < 0) return ERR_PTR(-EBADF);
fos = malloc(sizeof(struct apk_fd_ostream));
if (fos == NULL) {
close(fd);
- return NULL;
+ return ERR_PTR(-ENOMEM);
}
*fos = (struct apk_fd_ostream) {
@@ -742,14 +741,12 @@ struct apk_ostream *apk_ostream_to_file(int atfd,
int fd;
fd = openat(atfd, tmpfile ?: file, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC, mode);
- if (fd < 0)
- return NULL;
+ if (fd < 0) return ERR_PTR(-errno);
fcntl(fd, F_SETFD, FD_CLOEXEC);
os = apk_ostream_to_fd(fd);
- if (os == NULL)
- return NULL;
+ if (IS_ERR_OR_NULL(os)) return ERR_CAST(os);
if (tmpfile != NULL) {
struct apk_fd_ostream *fos =