diff options
author | Timo Teräs <timo.teras@iki.fi> | 2010-06-11 13:42:21 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2010-06-11 13:42:21 +0300 |
commit | 43cb554c3fd94ba394b708265c5fa2225a37a9eb (patch) | |
tree | ff9708008237754d46c3c2188cdb866a4d0fd195 /src/io.c | |
parent | bcbe575c3b28997a03a65426b241bdfef4d8b747 (diff) | |
download | apk-tools-43cb554c3fd94ba394b708265c5fa2225a37a9eb.tar.gz apk-tools-43cb554c3fd94ba394b708265c5fa2225a37a9eb.tar.bz2 apk-tools-43cb554c3fd94ba394b708265c5fa2225a37a9eb.tar.xz apk-tools-43cb554c3fd94ba394b708265c5fa2225a37a9eb.zip |
various: use O_CLOEXEC and add some error checking
Diffstat (limited to 'src/io.c')
-rw-r--r-- | src/io.c | 13 |
1 files changed, 5 insertions, 8 deletions
@@ -83,12 +83,10 @@ struct apk_istream *apk_istream_from_file(int atfd, const char *file) { int fd; - fd = openat(atfd, file, O_RDONLY); + fd = openat(atfd, file, O_RDONLY | O_CLOEXEC); if (fd < 0) return NULL; - fcntl(fd, F_SETFD, FD_CLOEXEC); - return apk_istream_from_fd(fd); } @@ -348,11 +346,10 @@ struct apk_bstream *apk_bstream_from_file(int atfd, const char *file) { int fd; - fd = openat(atfd, file, O_RDONLY); + fd = openat(atfd, file, O_RDONLY | O_CLOEXEC); if (fd < 0) return NULL; - fcntl(fd, F_SETFD, FD_CLOEXEC); return apk_bstream_from_fd(fd); } @@ -394,7 +391,7 @@ struct apk_bstream *apk_bstream_tee(struct apk_bstream *from, int atfd, const ch struct apk_tee_bstream *tbs; int fd; - fd = openat(atfd, to, O_CREAT | O_RDWR | O_TRUNC, + fd = openat(atfd, to, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (fd < 0) return NULL; @@ -442,7 +439,7 @@ apk_blob_t apk_blob_from_file(int atfd, const char *file) struct stat st; char *buf; - fd = openat(atfd, file, O_RDONLY); + fd = openat(atfd, file, O_RDONLY | O_CLOEXEC); if (fd < 0) return APK_BLOB_NULL; @@ -648,7 +645,7 @@ struct apk_ostream *apk_ostream_to_file(int atfd, struct apk_ostream *os; int fd; - fd = openat(atfd, tmpfile ?: file, O_CREAT | O_RDWR | O_TRUNC, mode); + fd = openat(atfd, tmpfile ?: file, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC, mode); if (fd < 0) return NULL; |