2 * Copyright (c) 2003-2004 Tim Kientzle
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "archive_platform.h"
28 __FBSDID("$FreeBSD: src/lib/libarchive/archive_util.c,v 1.9 2005/02/23 06:57:04 kientzle Exp $");
30 #include <sys/types.h>
35 #include "archive_private.h"
38 archive_api_feature(void)
40 return (ARCHIVE_API_FEATURE);
44 archive_api_version(void)
46 return (ARCHIVE_API_VERSION);
52 return (PACKAGE_NAME " " PACKAGE_VERSION);
56 archive_errno(struct archive *a)
58 return (a->archive_error_number);
62 archive_error_string(struct archive *a)
65 if (a->error != NULL && *a->error != '\0')
68 return ("(Empty error message)");
73 archive_format(struct archive *a)
75 return (a->archive_format);
79 archive_format_name(struct archive *a)
81 return (a->archive_format_name);
86 archive_compression(struct archive *a)
88 return (a->compression_code);
92 archive_compression_name(struct archive *a)
94 return (a->compression_name);
99 * Return a count of the number of compressed bytes processed.
102 archive_position_compressed(struct archive *a)
104 return (a->raw_position);
108 * Return a count of the number of uncompressed bytes processed.
111 archive_position_uncompressed(struct archive *a)
113 return (a->file_position);
118 archive_set_error(struct archive *a, int error_number, const char *fmt, ...)
121 #ifdef HAVE_STRERROR_R
126 a->archive_error_number = error_number;
133 archive_string_vsprintf(&(a->error_string), fmt, ap);
134 if(error_number > 0) {
135 archive_strcat(&(a->error_string), ": ");
136 #ifdef HAVE_STRERROR_R
137 #ifdef STRERROR_R_CHAR_P
138 errp = strerror_r(error_number, errbuff, sizeof(errbuff));
140 strerror_r(error_number, errbuff, sizeof(errbuff));
144 /* Note: this is not threadsafe! */
145 errp = strerror(error_number);
147 archive_strcat(&(a->error_string), errp);
149 a->error = a->error_string.s;
154 __archive_errx(int retvalue, const char *msg)
156 static const char *msg1 = "Fatal Internal Error in libarchive: ";
157 write(2, msg1, strlen(msg1));
158 write(2, msg, strlen(msg));