From 255fd81d79c49f6e5dbdb0df371d8ec7de600917 Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Tue, 10 Mar 2015 13:15:58 +0200 Subject: rework error handling for write streams --- src/io.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/io.c') 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 = -- cgit v1.2.3-70-g09d2