summaryrefslogtreecommitdiffstats
path: root/lib/libarchive/archive_read_open_file.c
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2009-04-17 00:50:00 +0000
committerkientzle <kientzle@FreeBSD.org>2009-04-17 00:50:00 +0000
commitef74aa99b9472fb8e958a399ff6b19fd337b724d (patch)
treec31e0bf4145168c53a8e70873f148e6872051759 /lib/libarchive/archive_read_open_file.c
parent5387456c70c14b686b55a811d0f071abd3a49fd8 (diff)
downloadFreeBSD-src-ef74aa99b9472fb8e958a399ff6b19fd337b724d.zip
FreeBSD-src-ef74aa99b9472fb8e958a399ff6b19fd337b724d.tar.gz
Don't use the open callback, which is deprecated (because it's
never necessary). Also, simplify just a tad by delegating to read_open_fd() when we know the file descriptor, instead of duplicating that logic.
Diffstat (limited to 'lib/libarchive/archive_read_open_file.c')
-rw-r--r--lib/libarchive/archive_read_open_file.c42
1 files changed, 16 insertions, 26 deletions
diff --git a/lib/libarchive/archive_read_open_file.c b/lib/libarchive/archive_read_open_file.c
index eb44084..e77d447 100644
--- a/lib/libarchive/archive_read_open_file.c
+++ b/lib/libarchive/archive_read_open_file.c
@@ -55,7 +55,6 @@ struct read_FILE_data {
};
static int file_close(struct archive *, void *);
-static int file_open(struct archive *, void *);
static ssize_t file_read(struct archive *, void *, const void **buff);
#if ARCHIVE_API_VERSION < 2
static ssize_t file_skip(struct archive *, void *, size_t request);
@@ -66,45 +65,36 @@ static off_t file_skip(struct archive *, void *, off_t request);
int
archive_read_open_FILE(struct archive *a, FILE *f)
{
+ struct stat st;
struct read_FILE_data *mine;
+ size_t block_size = 128 * 1024;
+ void *b;
mine = (struct read_FILE_data *)malloc(sizeof(*mine));
- if (mine == NULL) {
- archive_set_error(a, ENOMEM, "No memory");
- return (ARCHIVE_FATAL);
- }
- mine->block_size = 128 * 1024;
- mine->buffer = malloc(mine->block_size);
- if (mine->buffer == NULL) {
+ b = malloc(block_size);
+ if (mine == NULL || b == NULL) {
archive_set_error(a, ENOMEM, "No memory");
free(mine);
+ free(b);
return (ARCHIVE_FATAL);
}
+ mine->block_size = block_size;
+ mine->buffer = b;
mine->f = f;
- /* Suppress skip by default. See below. */
- mine->can_skip = 0;
- return (archive_read_open2(a, mine, file_open, file_read,
- file_skip, file_close));
-}
-
-static int
-file_open(struct archive *a, void *client_data)
-{
- struct read_FILE_data *mine = (struct read_FILE_data *)client_data;
- struct stat st;
-
/*
- * If we can't fstat() the file, it may just be that
- * it's not a file. (FILE * objects can wrap many kinds
- * of I/O streams.)
+ * If we can't fstat() the file, it may just be that it's not
+ * a file. (FILE * objects can wrap many kinds of I/O
+ * streams, some of which don't support fileno()).)
*/
if (fstat(fileno(mine->f), &st) == 0 && S_ISREG(st.st_mode)) {
archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino);
- /* Enable the seek optimization for regular files. */
+ /* Enable the seek optimization only for regular files. */
mine->can_skip = 1;
- }
+ } else
+ mine->can_skip = 0;
- return (ARCHIVE_OK);
+ return (archive_read_open2(a, mine, NULL, file_read,
+ file_skip, file_close));
}
static ssize_t
OpenPOWER on IntegriCloud