archive_private.h revision 228761
1/*-
2 * Copyright (c) 2003-2007 Tim Kientzle
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * $FreeBSD: head/lib/libarchive/archive_private.h 201098 2009-12-28 02:58:14Z kientzle $
26 */
27
28#ifndef __LIBARCHIVE_BUILD
29#error This header is only to be used internally to libarchive.
30#endif
31
32#ifndef ARCHIVE_PRIVATE_H_INCLUDED
33#define	ARCHIVE_PRIVATE_H_INCLUDED
34
35#include "archive.h"
36#include "archive_string.h"
37
38#if defined(__GNUC__) && (__GNUC__ > 2 || \
39			  (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
40#define	__LA_DEAD	__attribute__((__noreturn__))
41#else
42#define	__LA_DEAD
43#endif
44
45#define	ARCHIVE_WRITE_MAGIC	(0xb0c5c0deU)
46#define	ARCHIVE_READ_MAGIC	(0xdeb0c5U)
47#define	ARCHIVE_WRITE_DISK_MAGIC (0xc001b0c5U)
48#define	ARCHIVE_READ_DISK_MAGIC (0xbadb0c5U)
49
50#define	ARCHIVE_STATE_ANY	0xFFFFU
51#define	ARCHIVE_STATE_NEW	1U
52#define	ARCHIVE_STATE_HEADER	2U
53#define	ARCHIVE_STATE_DATA	4U
54#define	ARCHIVE_STATE_DATA_END	8U
55#define	ARCHIVE_STATE_EOF	0x10U
56#define	ARCHIVE_STATE_CLOSED	0x20U
57#define	ARCHIVE_STATE_FATAL	0x8000U
58
59struct archive_vtable {
60	int	(*archive_close)(struct archive *);
61	int	(*archive_finish)(struct archive *);
62	int	(*archive_write_header)(struct archive *,
63	    struct archive_entry *);
64	int	(*archive_write_finish_entry)(struct archive *);
65	ssize_t	(*archive_write_data)(struct archive *,
66	    const void *, size_t);
67	ssize_t	(*archive_write_data_block)(struct archive *,
68	    const void *, size_t, off_t);
69};
70
71struct archive {
72	/*
73	 * The magic/state values are used to sanity-check the
74	 * client's usage.  If an API function is called at a
75	 * ridiculous time, or the client passes us an invalid
76	 * pointer, these values allow me to catch that.
77	 */
78	unsigned int	magic;
79	unsigned int	state;
80
81	/*
82	 * Some public API functions depend on the "real" type of the
83	 * archive object.
84	 */
85	struct archive_vtable *vtable;
86
87	int		  archive_format;
88	const char	 *archive_format_name;
89
90	int	  compression_code;	/* Currently active compression. */
91	const char *compression_name;
92
93	/* Position in UNCOMPRESSED data stream. */
94	int64_t		  file_position;
95	/* Position in COMPRESSED data stream. */
96	int64_t		  raw_position;
97	/* Number of file entries processed. */
98	int		  file_count;
99
100	int		  archive_error_number;
101	const char	 *error;
102	struct archive_string	error_string;
103};
104
105/* Check magic value and state; exit if it isn't valid. */
106void	__archive_check_magic(struct archive *, unsigned int magic,
107	    unsigned int state, const char *func);
108
109void	__archive_errx(int retvalue, const char *msg) __LA_DEAD;
110
111int	__archive_parse_options(const char *p, const char *fn,
112	    int keysize, char *key, int valsize, char *val);
113
114#define	err_combine(a,b)	((a) < (b) ? (a) : (b))
115
116#if defined(__BORLANDC__) || (defined(_MSC_VER) &&  _MSC_VER <= 1300)
117# define	ARCHIVE_LITERAL_LL(x)	x##i64
118# define	ARCHIVE_LITERAL_ULL(x)	x##ui64
119#else
120# define	ARCHIVE_LITERAL_LL(x)	x##ll
121# define	ARCHIVE_LITERAL_ULL(x)	x##ull
122#endif
123
124#endif
125