diff options
author | Timo Teras <timo.teras@iki.fi> | 2008-11-27 16:59:04 +0200 |
---|---|---|
committer | Timo Teras <timo.teras@iki.fi> | 2008-11-27 16:59:04 +0200 |
commit | 1a7f3e3678844165d2660ebff09da26b9ba01576 (patch) | |
tree | d2b960a3612249d1ac975e18bb98096a6e2a2df5 /src/io.c | |
parent | 8e23a2ba4eb7f6192c6bce8a6da81004803eca3f (diff) | |
download | apk-tools-1a7f3e3678844165d2660ebff09da26b9ba01576.tar.gz apk-tools-1a7f3e3678844165d2660ebff09da26b9ba01576.tar.bz2 apk-tools-1a7f3e3678844165d2660ebff09da26b9ba01576.tar.xz apk-tools-1a7f3e3678844165d2660ebff09da26b9ba01576.zip |
various: use apk_istream api
Diffstat (limited to 'src/io.c')
-rw-r--r-- | src/io.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -305,6 +305,35 @@ apk_blob_t apk_blob_from_istream(struct apk_istream *is, size_t size) return APK_BLOB_PTR_LEN(ptr, rsize); } +apk_blob_t apk_blob_from_file(const char *file) +{ + int fd; + struct stat st; + char *buf; + + fd = open(file, O_RDONLY); + if (fd < 0) + return APK_BLOB_NULL; + + if (fstat(fd, &st) < 0) + goto err_fd; + + buf = malloc(st.st_size); + if (buf == NULL) + goto err_fd; + + if (read(fd, buf, st.st_size) != st.st_size) + goto err_read; + + close(fd); + return APK_BLOB_PTR_LEN(buf, st.st_size); +err_read: + free(buf); +err_fd: + close(fd); + return APK_BLOB_NULL; +} + int apk_file_get_info(const char *filename, struct apk_file_info *fi) { struct stat st; |