diff options
author | Timo Teräs <timo.teras@iki.fi> | 2015-03-10 13:15:58 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2015-03-10 13:15:58 +0200 |
commit | 255fd81d79c49f6e5dbdb0df371d8ec7de600917 (patch) | |
tree | a2e60a2e8048832c5b15afef86943505261c1ad4 | |
parent | 2a6896b2b4809849441756046ee7d8ad34abab34 (diff) | |
download | apk-tools-255fd81d79c49f6e5dbdb0df371d8ec7de600917.tar.gz apk-tools-255fd81d79c49f6e5dbdb0df371d8ec7de600917.tar.bz2 apk-tools-255fd81d79c49f6e5dbdb0df371d8ec7de600917.tar.xz apk-tools-255fd81d79c49f6e5dbdb0df371d8ec7de600917.zip |
rework error handling for write streams
-rw-r--r-- | src/database.c | 28 | ||||
-rw-r--r-- | src/index.c | 1 | ||||
-rw-r--r-- | src/info.c | 8 | ||||
-rw-r--r-- | src/io.c | 11 |
4 files changed, 19 insertions, 29 deletions
diff --git a/src/database.c b/src/database.c index bbf5a9d..44d0b20 100644 --- a/src/database.c +++ b/src/database.c @@ -1187,8 +1187,7 @@ static int apk_db_index_write_nr_cache(struct apk_database *db) "installed", "installed.new", 0644); - if (os == NULL) - return -EIO; + if (IS_ERR_OR_NULL(os)) return PTR_ERR(os); ctx.os = os; list_for_each_entry(ipkg, &db->installed.packages, installed_pkgs_list) { @@ -1648,36 +1647,29 @@ int apk_db_write_config(struct apk_database *db) apk_world_file, apk_world_file_tmp, 0644); - if (os == NULL) - return -1; - + if (IS_ERR_OR_NULL(os)) return PTR_ERR(os); apk_deps_write(db, db->world, os, APK_BLOB_PTR_LEN("\n", 1)); os->write(os, "\n", 1); r = os->close(os); - if (r < 0) - return r; + if (r < 0) return r; os = apk_ostream_to_file(db->root_fd, apk_installed_file, apk_installed_file_tmp, 0644); - if (os == NULL) - return -1; + if (IS_ERR_OR_NULL(os)) return PTR_ERR(os); apk_db_write_fdb(db, os); r = os->close(os); - if (r < 0) - return r; + if (r < 0) return r; os = apk_ostream_to_file(db->root_fd, apk_scripts_file, apk_scripts_file_tmp, 0644); - if (os == NULL) - return -1; + if (IS_ERR_OR_NULL(os)) return PTR_ERR(os); apk_db_scriptdb_write(db, os); r = os->close(os); - if (r < 0) - return r; + if (r < 0) return r; apk_db_index_write_nr_cache(db); @@ -1685,12 +1677,10 @@ int apk_db_write_config(struct apk_database *db) apk_triggers_file, apk_triggers_file_tmp, 0644); - if (os == NULL) - return -1; + if (IS_ERR_OR_NULL(os)) return PTR_ERR(os); apk_db_triggers_write(db, os); r = os->close(os); - if (r < 0) - return r; + if (r < 0) return r; return 0; } diff --git a/src/index.c b/src/index.c index 2fe8cb4..ccb4713 100644 --- a/src/index.c +++ b/src/index.c @@ -205,6 +205,7 @@ static int index_main(void *ctx, struct apk_database *db, struct apk_string_arra os = apk_ostream_to_file(AT_FDCWD, ictx->output, NULL, 0644); else os = apk_ostream_to_fd(STDOUT_FILENO); + if (IS_ERR_OR_NULL(os)) return -1; if (ictx->method == APK_SIGN_GENERATE) { struct apk_ostream *counter; @@ -130,9 +130,11 @@ static void info_who_owns(struct info_ctx *ctx, struct apk_database *db, } if (apk_verbosity < 1 && deps->num != 0) { os = apk_ostream_to_fd(STDOUT_FILENO); - apk_deps_write(db, deps, os, APK_BLOB_PTR_LEN(" ", 1)); - os->write(os, "\n", 1); - os->close(os); + if (!IS_ERR_OR_NULL(os)) { + apk_deps_write(db, deps, os, APK_BLOB_PTR_LEN(" ", 1)); + os->write(os, "\n", 1); + os->close(os); + } } apk_dependency_array_free(&deps); } @@ -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 = |