698ad2258c35a98706149fb92472dd64877872ac
[dragonfly.git] / contrib / libarchive / libarchive / archive_private.h
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: src/lib/libarchive/archive_private.h,v 1.32 2008/12/06 06:23:37 kientzle Exp $
26  */
27
28 #ifndef ARCHIVE_PRIVATE_H_INCLUDED
29 #define ARCHIVE_PRIVATE_H_INCLUDED
30
31 #include "archive.h"
32 #include "archive_string.h"
33
34 #if defined(__GNUC__) && (__GNUC__ > 2 || \
35                           (__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
36 #define __LA_DEAD       __attribute__((__noreturn__))
37 #else
38 #define __LA_DEAD
39 #endif
40
41 #define ARCHIVE_WRITE_MAGIC     (0xb0c5c0deU)
42 #define ARCHIVE_READ_MAGIC      (0xdeb0c5U)
43 #define ARCHIVE_WRITE_DISK_MAGIC (0xc001b0c5U)
44 #define ARCHIVE_READ_DISK_MAGIC (0xbadb0c5U)
45
46 #define ARCHIVE_STATE_ANY       0xFFFFU
47 #define ARCHIVE_STATE_NEW       1U
48 #define ARCHIVE_STATE_HEADER    2U
49 #define ARCHIVE_STATE_DATA      4U
50 #define ARCHIVE_STATE_DATA_END  8U
51 #define ARCHIVE_STATE_EOF       0x10U
52 #define ARCHIVE_STATE_CLOSED    0x20U
53 #define ARCHIVE_STATE_FATAL     0x8000U
54
55 struct archive_vtable {
56         int     (*archive_close)(struct archive *);
57         int     (*archive_finish)(struct archive *);
58         int     (*archive_write_header)(struct archive *,
59             struct archive_entry *);
60         int     (*archive_write_finish_entry)(struct archive *);
61         ssize_t (*archive_write_data)(struct archive *,
62             const void *, size_t);
63         ssize_t (*archive_write_data_block)(struct archive *,
64             const void *, size_t, off_t);
65 };
66
67 struct archive {
68         /*
69          * The magic/state values are used to sanity-check the
70          * client's usage.  If an API function is called at a
71          * ridiculous time, or the client passes us an invalid
72          * pointer, these values allow me to catch that.
73          */
74         unsigned int    magic;
75         unsigned int    state;
76
77         /*
78          * Some public API functions depend on the "real" type of the
79          * archive object.
80          */
81         struct archive_vtable *vtable;
82
83         int               archive_format;
84         const char       *archive_format_name;
85
86         int       compression_code;     /* Currently active compression. */
87         const char *compression_name;
88
89         /* Position in UNCOMPRESSED data stream. */
90         int64_t           file_position;
91         /* Position in COMPRESSED data stream. */
92         int64_t           raw_position;
93
94         int               archive_error_number;
95         const char       *error;
96         struct archive_string   error_string;
97 };
98
99 /* Check magic value and state; exit if it isn't valid. */
100 void    __archive_check_magic(struct archive *, unsigned int magic,
101             unsigned int state, const char *func);
102
103 void    __archive_errx(int retvalue, const char *msg) __LA_DEAD;
104
105 int     __archive_parse_options(const char *p, const char *fn,
106             int keysize, char *key, int valsize, char *val);
107
108 #define err_combine(a,b)        ((a) < (b) ? (a) : (b))
109
110 #endif