archive_private.h revision 267654
1184610Salfred/*-
2184610Salfred * Copyright (c) 2003-2007 Tim Kientzle
3184610Salfred * All rights reserved.
4184610Salfred *
5184610Salfred * Redistribution and use in source and binary forms, with or without
6184610Salfred * modification, are permitted provided that the following conditions
7184610Salfred * are met:
8184610Salfred * 1. Redistributions of source code must retain the above copyright
9184610Salfred *    notice, this list of conditions and the following disclaimer.
10184610Salfred * 2. Redistributions in binary form must reproduce the above copyright
11184610Salfred *    notice, this list of conditions and the following disclaimer in the
12184610Salfred *    documentation and/or other materials provided with the distribution.
13184610Salfred *
14184610Salfred * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15184610Salfred * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16184610Salfred * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17184610Salfred * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18184610Salfred * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19184610Salfred * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20184610Salfred * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21184610Salfred * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22184610Salfred * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23184610Salfred * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24184610Salfred *
25184610Salfred * $FreeBSD: releng/9.3/contrib/libarchive/libarchive/archive_private.h 229592 2012-01-05 12:06:54Z mm $
26184610Salfred */
27246122Shselasky
28246122Shselasky#ifndef __LIBARCHIVE_BUILD
29246122Shselasky#error This header is only to be used internally to libarchive.
30194677Sthompsa#endif
31194677Sthompsa
32194677Sthompsa#ifndef ARCHIVE_PRIVATE_H_INCLUDED
33194677Sthompsa#define	ARCHIVE_PRIVATE_H_INCLUDED
34194677Sthompsa
35194677Sthompsa#include "archive.h"
36194677Sthompsa#include "archive_string.h"
37194677Sthompsa
38194677Sthompsa#if defined(__GNUC__) && (__GNUC__ > 2 || \
39194677Sthompsa			  (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
40194677Sthompsa#define	__LA_DEAD	__attribute__((__noreturn__))
41194677Sthompsa#else
42194677Sthompsa#define	__LA_DEAD
43194677Sthompsa#endif
44194677Sthompsa
45194677Sthompsa#define	ARCHIVE_WRITE_MAGIC	(0xb0c5c0deU)
46194677Sthompsa#define	ARCHIVE_READ_MAGIC	(0xdeb0c5U)
47194677Sthompsa#define	ARCHIVE_WRITE_DISK_MAGIC (0xc001b0c5U)
48223538Shselasky#define	ARCHIVE_READ_DISK_MAGIC (0xbadb0c5U)
49223538Shselasky
50184610Salfred#define	ARCHIVE_STATE_ANY	0xFFFFU
51194677Sthompsa#define	ARCHIVE_STATE_NEW	1U
52194677Sthompsa#define	ARCHIVE_STATE_HEADER	2U
53246122Shselasky#define	ARCHIVE_STATE_DATA	4U
54194677Sthompsa#define	ARCHIVE_STATE_DATA_END	8U
55184610Salfred#define	ARCHIVE_STATE_EOF	0x10U
56194228Sthompsa#define	ARCHIVE_STATE_CLOSED	0x20U
57184610Salfred#define	ARCHIVE_STATE_FATAL	0x8000U
58192984Sthompsa
59194228Sthompsastruct archive_vtable {
60184610Salfred	int	(*archive_close)(struct archive *);
61184610Salfred	int	(*archive_free)(struct archive *);
62192984Sthompsa	int	(*archive_write_header)(struct archive *,
63184610Salfred	    struct archive_entry *);
64184610Salfred	int	(*archive_write_finish_entry)(struct archive *);
65184610Salfred	ssize_t	(*archive_write_data)(struct archive *,
66184610Salfred	    const void *, size_t);
67184610Salfred	ssize_t	(*archive_write_data_block)(struct archive *,
68184610Salfred	    const void *, size_t, off_t);
69192984Sthompsa};
70194228Sthompsa
71194228Sthompsastruct archive {
72184610Salfred	/*
73192984Sthompsa	 * The magic/state values are used to sanity-check the
74184610Salfred	 * client's usage.  If an API function is called at a
75184610Salfred	 * ridiculous time, or the client passes us an invalid
76184610Salfred	 * pointer, these values allow me to catch that.
77184610Salfred	 */
78184610Salfred	unsigned int	magic;
79184610Salfred	unsigned int	state;
80184610Salfred
81184610Salfred	/*
82184610Salfred	 * Some public API functions depend on the "real" type of the
83184610Salfred	 * archive object.
84184610Salfred	 */
85184610Salfred	struct archive_vtable *vtable;
86184610Salfred
87184610Salfred	int		  archive_format;
88184610Salfred	const char	 *archive_format_name;
89184610Salfred
90184610Salfred	int	  compression_code;	/* Currently active compression. */
91184610Salfred	const char *compression_name;
92184610Salfred
93184610Salfred	/* Position in UNCOMPRESSED data stream. */
94184610Salfred	int64_t		  file_position;
95184610Salfred	/* Position in COMPRESSED data stream. */
96184610Salfred	int64_t		  raw_position;
97184610Salfred	/* Number of file entries processed. */
98184610Salfred	int		  file_count;
99184610Salfred
100184610Salfred	int		  archive_error_number;
101184610Salfred	const char	 *error;
102184610Salfred	struct archive_string	error_string;
103184610Salfred};
104184610Salfred
105184610Salfred/* Check magic value and state; exit if it isn't valid. */
106184610Salfredvoid	__archive_check_magic(struct archive *, unsigned int magic,
107184610Salfred	    unsigned int state, const char *func);
108184610Salfred
109184610Salfredvoid	__archive_errx(int retvalue, const char *msg) __LA_DEAD;
110184610Salfred
111184610Salfredint	__archive_parse_options(const char *p, const char *fn,
112184610Salfred	    int keysize, char *key, int valsize, char *val);
113184610Salfred
114184610Salfred#define	err_combine(a,b)	((a) < (b) ? (a) : (b))
115184610Salfred
116184610Salfred#if defined(__BORLANDC__) || (defined(_MSC_VER) &&  _MSC_VER <= 1300)
117184610Salfred# define	ARCHIVE_LITERAL_LL(x)	x##i64
118184610Salfred# define	ARCHIVE_LITERAL_ULL(x)	x##ui64
119184610Salfred#else
120184610Salfred# define	ARCHIVE_LITERAL_LL(x)	x##ll
121184610Salfred# define	ARCHIVE_LITERAL_ULL(x)	x##ull
122184610Salfred#endif
123184610Salfred
124184610Salfred#endif
125184610Salfred