summaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2012-02-23 17:04:51 +0200
committerTimo Teräs <timo.teras@iki.fi>2012-02-23 17:04:51 +0200
commit7392acb95ea7be1317892aad1b69a01382ee3f5c (patch)
treeb97a25dce86bedc25f07f0f0275b67519c0521a2 /src/io.c
parenta9a84215c70c746b2f6a6b3c58c338730100666c (diff)
downloadapk-tools-7392acb95ea7be1317892aad1b69a01382ee3f5c.tar.gz
apk-tools-7392acb95ea7be1317892aad1b69a01382ee3f5c.tar.bz2
apk-tools-7392acb95ea7be1317892aad1b69a01382ee3f5c.tar.xz
apk-tools-7392acb95ea7be1317892aad1b69a01382ee3f5c.zip
db: keep architecture in $ROOT/etc/apk/arch
This we use proper arch in case modifying chroot installation.
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/io.c b/src/io.c
index 0ae46f0..c14cc23 100644
--- a/src/io.c
+++ b/src/io.c
@@ -486,6 +486,36 @@ err_fd:
return APK_BLOB_NULL;
}
+int apk_blob_to_file(int atfd, const char *file, apk_blob_t b, unsigned int flags)
+{
+ int fd, r, len;
+
+ fd = openat(atfd, file, O_CREAT | O_WRONLY | O_CLOEXEC, 0644);
+ if (fd < 0)
+ return -errno;
+
+ len = b.len;
+ r = write(fd, b.ptr, len);
+ if ((r == len) &&
+ (flags & APK_BTF_ADD_EOL) && (b.len == 0 || b.ptr[b.len-1] != '\n')) {
+ len = 1;
+ r = write(fd, "\n", len);
+ }
+
+ if (r < 0)
+ r = -errno;
+ else if (r != len)
+ r = -ENOSPC;
+ else
+ r = 0;
+ close(fd);
+
+ if (r != 0)
+ unlinkat(atfd, file, 0);
+
+ return r;
+}
+
int apk_file_get_info(int atfd, const char *filename, unsigned int flags,
struct apk_file_info *fi)
{