More -Wwrite-strings cleanup and make sure you can actually play it.
[dragonfly.git] / contrib / libarchive / archive_util.c
blob2050bb02b5929d48208452a67d2b59cc944ccc72
1 /*-
2 * Copyright (c) 2003-2004 Tim Kientzle
3 * All rights reserved.
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 * 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>
31 #include <stdlib.h>
32 #include <string.h>
34 #include "archive.h"
35 #include "archive_private.h"
37 int
38 archive_api_feature(void)
40 return (ARCHIVE_API_FEATURE);
43 int
44 archive_api_version(void)
46 return (ARCHIVE_API_VERSION);
49 const char *
50 archive_version(void)
52 return (PACKAGE_NAME " " PACKAGE_VERSION);
55 int
56 archive_errno(struct archive *a)
58 return (a->archive_error_number);
61 const char *
62 archive_error_string(struct archive *a)
65 if (a->error != NULL && *a->error != '\0')
66 return (a->error);
67 else
68 return ("(Empty error message)");
72 int
73 archive_format(struct archive *a)
75 return (a->archive_format);
78 const char *
79 archive_format_name(struct archive *a)
81 return (a->archive_format_name);
85 int
86 archive_compression(struct archive *a)
88 return (a->compression_code);
91 const char *
92 archive_compression_name(struct archive *a)
94 return (a->compression_name);
99 * Return a count of the number of compressed bytes processed.
101 int64_t
102 archive_position_compressed(struct archive *a)
104 return (a->raw_position);
108 * Return a count of the number of uncompressed bytes processed.
110 int64_t
111 archive_position_uncompressed(struct archive *a)
113 return (a->file_position);
117 void
118 archive_set_error(struct archive *a, int error_number, const char *fmt, ...)
120 va_list ap;
121 #ifdef HAVE_STRERROR_R
122 char errbuff[512];
123 #endif
124 char *errp;
126 a->archive_error_number = error_number;
127 if (fmt == NULL) {
128 a->error = NULL;
129 return;
132 va_start(ap, fmt);
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));
139 #else
140 strerror_r(error_number, errbuff, sizeof(errbuff));
141 errp = errbuff;
142 #endif
143 #else
144 /* Note: this is not threadsafe! */
145 errp = strerror(error_number);
146 #endif
147 archive_strcat(&(a->error_string), errp);
149 a->error = a->error_string.s;
150 va_end(ap);
153 void
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));
159 write(2, "\n", 1);
160 exit(retvalue);