summaryrefslogtreecommitdiffstats
path: root/src/io.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2010-06-11 13:42:21 +0300
committerTimo Teräs <timo.teras@iki.fi>2010-06-11 13:42:21 +0300
commit43cb554c3fd94ba394b708265c5fa2225a37a9eb (patch)
treeff9708008237754d46c3c2188cdb866a4d0fd195 /src/io.c
parentbcbe575c3b28997a03a65426b241bdfef4d8b747 (diff)
downloadapk-tools-43cb554c3fd94ba394b708265c5fa2225a37a9eb.tar.bz2
apk-tools-43cb554c3fd94ba394b708265c5fa2225a37a9eb.tar.xz
various: use O_CLOEXEC and add some error checking
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/io.c b/src/io.c
index 3e292a7..57e2d2d 100644
--- a/src/io.c
+++ b/src/io.c
@@ -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;