160b4ad09SPeter Avalos /*-
260b4ad09SPeter Avalos  * Copyright (c) 2003-2007 Tim Kientzle
360b4ad09SPeter Avalos  * All rights reserved.
460b4ad09SPeter Avalos  *
560b4ad09SPeter Avalos  * Redistribution and use in source and binary forms, with or without
660b4ad09SPeter Avalos  * modification, are permitted provided that the following conditions
760b4ad09SPeter Avalos  * are met:
860b4ad09SPeter Avalos  * 1. Redistributions of source code must retain the above copyright
960b4ad09SPeter Avalos  *    notice, this list of conditions and the following disclaimer.
1060b4ad09SPeter Avalos  * 2. Redistributions in binary form must reproduce the above copyright
1160b4ad09SPeter Avalos  *    notice, this list of conditions and the following disclaimer in the
1260b4ad09SPeter Avalos  *    documentation and/or other materials provided with the distribution.
1360b4ad09SPeter Avalos  *
1460b4ad09SPeter Avalos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
1560b4ad09SPeter Avalos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1660b4ad09SPeter Avalos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1760b4ad09SPeter Avalos  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
1860b4ad09SPeter Avalos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1960b4ad09SPeter Avalos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2060b4ad09SPeter Avalos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2160b4ad09SPeter Avalos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2260b4ad09SPeter Avalos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2360b4ad09SPeter Avalos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2460b4ad09SPeter Avalos  */
2560b4ad09SPeter Avalos 
2660b4ad09SPeter Avalos #include "archive_platform.h"
279c82a63eSPeter Avalos __FBSDID("$FreeBSD: head/lib/libarchive/archive_virtual.c 201098 2009-12-28 02:58:14Z kientzle $");
2860b4ad09SPeter Avalos 
2960b4ad09SPeter Avalos #include "archive.h"
3060b4ad09SPeter Avalos #include "archive_entry.h"
3160b4ad09SPeter Avalos #include "archive_private.h"
3260b4ad09SPeter Avalos 
3360b4ad09SPeter Avalos int
archive_filter_code(struct archive * a,int n)34c09f92d2SPeter Avalos archive_filter_code(struct archive *a, int n)
35c09f92d2SPeter Avalos {
36c09f92d2SPeter Avalos 	return ((a->vtable->archive_filter_code)(a, n));
37c09f92d2SPeter Avalos }
38c09f92d2SPeter Avalos 
39c09f92d2SPeter Avalos int
archive_filter_count(struct archive * a)40c09f92d2SPeter Avalos archive_filter_count(struct archive *a)
41c09f92d2SPeter Avalos {
42c09f92d2SPeter Avalos 	return ((a->vtable->archive_filter_count)(a));
43c09f92d2SPeter Avalos }
44c09f92d2SPeter Avalos 
45c09f92d2SPeter Avalos const char *
archive_filter_name(struct archive * a,int n)46c09f92d2SPeter Avalos archive_filter_name(struct archive *a, int n)
47c09f92d2SPeter Avalos {
48c09f92d2SPeter Avalos 	return ((a->vtable->archive_filter_name)(a, n));
49c09f92d2SPeter Avalos }
50c09f92d2SPeter Avalos 
51e95abc47Szrj la_int64_t
archive_filter_bytes(struct archive * a,int n)52c09f92d2SPeter Avalos archive_filter_bytes(struct archive *a, int n)
53c09f92d2SPeter Avalos {
54c09f92d2SPeter Avalos 	return ((a->vtable->archive_filter_bytes)(a, n));
55c09f92d2SPeter Avalos }
56c09f92d2SPeter Avalos 
57c09f92d2SPeter Avalos int
archive_free(struct archive * a)586b384f39SPeter Avalos archive_free(struct archive *a)
596b384f39SPeter Avalos {
606b384f39SPeter Avalos 	if (a == NULL)
616b384f39SPeter Avalos 		return (ARCHIVE_OK);
626b384f39SPeter Avalos 	return ((a->vtable->archive_free)(a));
636b384f39SPeter Avalos }
646b384f39SPeter Avalos 
656b384f39SPeter Avalos int
archive_write_close(struct archive * a)6660b4ad09SPeter Avalos archive_write_close(struct archive *a)
6760b4ad09SPeter Avalos {
688029ab02SPeter Avalos 	return ((a->vtable->archive_close)(a));
698029ab02SPeter Avalos }
708029ab02SPeter Avalos 
718029ab02SPeter Avalos int
archive_read_close(struct archive * a)728029ab02SPeter Avalos archive_read_close(struct archive *a)
738029ab02SPeter Avalos {
748029ab02SPeter Avalos 	return ((a->vtable->archive_close)(a));
7560b4ad09SPeter Avalos }
7660b4ad09SPeter Avalos 
77c09f92d2SPeter Avalos int
archive_write_fail(struct archive * a)78d4d8193eSPeter Avalos archive_write_fail(struct archive *a)
79d4d8193eSPeter Avalos {
80d4d8193eSPeter Avalos 	a->state = ARCHIVE_STATE_FATAL;
81d4d8193eSPeter Avalos 	return a->state;
82d4d8193eSPeter Avalos }
83d4d8193eSPeter Avalos 
84d4d8193eSPeter Avalos int
archive_write_free(struct archive * a)85c09f92d2SPeter Avalos archive_write_free(struct archive *a)
86c09f92d2SPeter Avalos {
876b384f39SPeter Avalos 	return archive_free(a);
88c09f92d2SPeter Avalos }
89c09f92d2SPeter Avalos 
90c09f92d2SPeter Avalos #if ARCHIVE_VERSION_NUMBER < 4000000
91c09f92d2SPeter Avalos /* For backwards compatibility; will be removed with libarchive 4.0. */
9260b4ad09SPeter Avalos int
archive_write_finish(struct archive * a)9360b4ad09SPeter Avalos archive_write_finish(struct archive *a)
9460b4ad09SPeter Avalos {
9555c601bbSPeter Avalos 	return archive_write_free(a);
9660b4ad09SPeter Avalos }
9760b4ad09SPeter Avalos #endif
9860b4ad09SPeter Avalos 
9960b4ad09SPeter Avalos int
archive_read_free(struct archive * a)100c09f92d2SPeter Avalos archive_read_free(struct archive *a)
101c09f92d2SPeter Avalos {
1026b384f39SPeter Avalos 	return archive_free(a);
103c09f92d2SPeter Avalos }
104c09f92d2SPeter Avalos 
105c09f92d2SPeter Avalos #if ARCHIVE_VERSION_NUMBER < 4000000
106c09f92d2SPeter Avalos /* For backwards compatibility; will be removed with libarchive 4.0. */
107c09f92d2SPeter Avalos int
archive_read_finish(struct archive * a)1088029ab02SPeter Avalos archive_read_finish(struct archive *a)
1098029ab02SPeter Avalos {
11055c601bbSPeter Avalos 	return archive_read_free(a);
1118029ab02SPeter Avalos }
112c09f92d2SPeter Avalos #endif
1138029ab02SPeter Avalos 
1148029ab02SPeter Avalos int
archive_write_header(struct archive * a,struct archive_entry * entry)11560b4ad09SPeter Avalos archive_write_header(struct archive *a, struct archive_entry *entry)
11660b4ad09SPeter Avalos {
1179c82a63eSPeter Avalos 	++a->file_count;
11860b4ad09SPeter Avalos 	return ((a->vtable->archive_write_header)(a, entry));
11960b4ad09SPeter Avalos }
12060b4ad09SPeter Avalos 
12160b4ad09SPeter Avalos int
archive_write_finish_entry(struct archive * a)12260b4ad09SPeter Avalos archive_write_finish_entry(struct archive *a)
12360b4ad09SPeter Avalos {
12460b4ad09SPeter Avalos 	return ((a->vtable->archive_write_finish_entry)(a));
12560b4ad09SPeter Avalos }
12660b4ad09SPeter Avalos 
127e95abc47Szrj la_ssize_t
archive_write_data(struct archive * a,const void * buff,size_t s)12860b4ad09SPeter Avalos archive_write_data(struct archive *a, const void *buff, size_t s)
12960b4ad09SPeter Avalos {
13060b4ad09SPeter Avalos 	return ((a->vtable->archive_write_data)(a, buff, s));
13160b4ad09SPeter Avalos }
13260b4ad09SPeter Avalos 
133e95abc47Szrj la_ssize_t
archive_write_data_block(struct archive * a,const void * buff,size_t s,la_int64_t o)134e95abc47Szrj archive_write_data_block(struct archive *a, const void *buff, size_t s,
135e95abc47Szrj     la_int64_t o)
13660b4ad09SPeter Avalos {
137c09f92d2SPeter Avalos 	if (a->vtable->archive_write_data_block == NULL) {
138c09f92d2SPeter Avalos 		archive_set_error(a, ARCHIVE_ERRNO_MISC,
139c09f92d2SPeter Avalos 		    "archive_write_data_block not supported");
140c09f92d2SPeter Avalos 		a->state = ARCHIVE_STATE_FATAL;
141c09f92d2SPeter Avalos 		return (ARCHIVE_FATAL);
142c09f92d2SPeter Avalos 	}
14360b4ad09SPeter Avalos 	return ((a->vtable->archive_write_data_block)(a, buff, s, o));
14460b4ad09SPeter Avalos }
145c09f92d2SPeter Avalos 
146c09f92d2SPeter Avalos int
archive_read_next_header(struct archive * a,struct archive_entry ** entry)147c09f92d2SPeter Avalos archive_read_next_header(struct archive *a, struct archive_entry **entry)
148c09f92d2SPeter Avalos {
149c09f92d2SPeter Avalos 	return ((a->vtable->archive_read_next_header)(a, entry));
150c09f92d2SPeter Avalos }
151c09f92d2SPeter Avalos 
152c09f92d2SPeter Avalos int
archive_read_next_header2(struct archive * a,struct archive_entry * entry)153c09f92d2SPeter Avalos archive_read_next_header2(struct archive *a, struct archive_entry *entry)
154c09f92d2SPeter Avalos {
155c09f92d2SPeter Avalos 	return ((a->vtable->archive_read_next_header2)(a, entry));
156c09f92d2SPeter Avalos }
157c09f92d2SPeter Avalos 
158c09f92d2SPeter Avalos int
archive_read_data_block(struct archive * a,const void ** buff,size_t * s,la_int64_t * o)159c09f92d2SPeter Avalos archive_read_data_block(struct archive *a,
160e95abc47Szrj     const void **buff, size_t *s, la_int64_t *o)
161c09f92d2SPeter Avalos {
162c09f92d2SPeter Avalos 	return ((a->vtable->archive_read_data_block)(a, buff, s, o));
163c09f92d2SPeter Avalos }
164