libarchive-static 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/Makefile +6 -0
- data/ext/extconf.rb +61 -0
- data/ext/libarchive-0.1.1/COPYING.libarchive +60 -0
- data/ext/libarchive-0.1.1/LICENSE.libbzip2 +42 -0
- data/ext/libarchive-0.1.1/README.txt +143 -0
- data/ext/libarchive-0.1.1/ext/Makefile.in +0 -0
- data/ext/libarchive-0.1.1/ext/archive_read_support_compression.c +31 -0
- data/ext/libarchive-0.1.1/ext/archive_read_support_compression.h +6 -0
- data/ext/libarchive-0.1.1/ext/archive_read_support_format.c +32 -0
- data/ext/libarchive-0.1.1/ext/archive_read_support_format.h +6 -0
- data/ext/libarchive-0.1.1/ext/archive_write_open_rb_str.c +29 -0
- data/ext/libarchive-0.1.1/ext/archive_write_open_rb_str.h +6 -0
- data/ext/libarchive-0.1.1/ext/archive_write_set_compression.c +32 -0
- data/ext/libarchive-0.1.1/ext/archive_write_set_compression.h +6 -0
- data/ext/libarchive-0.1.1/ext/config.h.in +22 -0
- data/ext/libarchive-0.1.1/ext/configure +3904 -0
- data/ext/libarchive-0.1.1/ext/configure.in +11 -0
- data/ext/libarchive-0.1.1/ext/depend +19 -0
- data/ext/libarchive-0.1.1/ext/extconf.rb +6 -0
- data/ext/libarchive-0.1.1/ext/install-sh +250 -0
- data/ext/libarchive-0.1.1/ext/libarchive.c +89 -0
- data/ext/libarchive-0.1.1/ext/libarchive_archive.c +84 -0
- data/ext/libarchive-0.1.1/ext/libarchive_entry.c +1015 -0
- data/ext/libarchive-0.1.1/ext/libarchive_internal.h +155 -0
- data/ext/libarchive-0.1.1/ext/libarchive_reader.c +328 -0
- data/ext/libarchive-0.1.1/ext/libarchive_win32.h +52 -0
- data/ext/libarchive-0.1.1/ext/libarchive_writer.c +246 -0
- data/ext/libarchive-0.1.1/libarchive.c +1762 -0
- data/ext/libarchive-2.8.4/Makefile.in +7076 -0
- data/ext/libarchive-2.8.4/build/autoconf/check_stdcall_func.m4 +51 -0
- data/ext/libarchive-2.8.4/build/autoconf/compile +143 -0
- data/ext/libarchive-2.8.4/build/autoconf/config.guess +1502 -0
- data/ext/libarchive-2.8.4/build/autoconf/config.sub +1708 -0
- data/ext/libarchive-2.8.4/build/autoconf/depcomp +630 -0
- data/ext/libarchive-2.8.4/build/autoconf/install-sh +291 -0
- data/ext/libarchive-2.8.4/build/autoconf/la_uid_t.m4 +20 -0
- data/ext/libarchive-2.8.4/build/autoconf/ltmain.sh +8406 -0
- data/ext/libarchive-2.8.4/build/autoconf/missing +376 -0
- data/ext/libarchive-2.8.4/build/pkgconfig/libarchive.pc.in +10 -0
- data/ext/libarchive-2.8.4/config.h.in +772 -0
- data/ext/libarchive-2.8.4/configure +17916 -0
- data/ext/libarchive-2.8.4/libarchive/archive.h +741 -0
- data/ext/libarchive-2.8.4/libarchive/archive_check_magic.c +134 -0
- data/ext/libarchive-2.8.4/libarchive/archive_crc32.h +66 -0
- data/ext/libarchive-2.8.4/libarchive/archive_endian.h +162 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry.c +2202 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry.h +524 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_copy_bhfi.c +74 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_copy_stat.c +77 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_link_resolver.c +405 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_private.h +184 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_stat.c +118 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_strmode.c +87 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_xattr.c +158 -0
- data/ext/libarchive-2.8.4/libarchive/archive_hash.h +281 -0
- data/ext/libarchive-2.8.4/libarchive/archive_platform.h +165 -0
- data/ext/libarchive-2.8.4/libarchive/archive_private.h +124 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read.c +1249 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_data_into_fd.c +93 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_disk.c +198 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_disk_entry_from_file.c +570 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_disk_private.h +62 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_disk_set_standard_lookup.c +303 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_extract.c +182 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_open_fd.c +190 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_open_file.c +165 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_open_filename.c +272 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_open_memory.c +156 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_private.h +199 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_all.c +60 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_bzip2.c +353 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_compress.c +444 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_gzip.c +465 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_none.c +40 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_program.c +459 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_rpm.c +287 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_uu.c +627 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_xz.c +708 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_all.c +43 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_ar.c +584 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_cpio.c +777 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_empty.c +93 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_iso9660.c +2830 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_mtree.c +1304 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_raw.c +185 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_tar.c +2418 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_xar.c +3151 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_zip.c +903 -0
- data/ext/libarchive-2.8.4/libarchive/archive_string.c +453 -0
- data/ext/libarchive-2.8.4/libarchive/archive_string.h +148 -0
- data/ext/libarchive-2.8.4/libarchive/archive_string_sprintf.c +164 -0
- data/ext/libarchive-2.8.4/libarchive/archive_util.c +391 -0
- data/ext/libarchive-2.8.4/libarchive/archive_virtual.c +94 -0
- data/ext/libarchive-2.8.4/libarchive/archive_windows.c +1236 -0
- data/ext/libarchive-2.8.4/libarchive/archive_windows.h +347 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write.c +466 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_disk.c +2628 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_disk_private.h +38 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_disk_set_standard_lookup.c +262 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_open_fd.c +141 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_open_file.c +105 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_open_filename.c +162 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_open_memory.c +126 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_private.h +122 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_bzip2.c +408 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_compress.c +492 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_gzip.c +477 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_none.c +257 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_program.c +347 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_xz.c +438 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format.c +72 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_ar.c +550 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_by_name.c +76 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_cpio.c +344 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_cpio_newc.c +295 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_mtree.c +1050 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_pax.c +1386 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_shar.c +626 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_ustar.c +587 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_zip.c +667 -0
- data/ext/libarchive-2.8.4/libarchive/config_freebsd.h +154 -0
- data/ext/libarchive-2.8.4/libarchive/filter_fork.c +161 -0
- data/ext/libarchive-2.8.4/libarchive/filter_fork.h +41 -0
- data/ext/libarchive-2.8.4/libarchive/filter_fork_windows.c +113 -0
- data/ext/libarchive-static-makefile +80 -0
- data/ext/libarchive-static-wrapper-makefile +22 -0
- data/ext/zlib-1.2.5/Makefile.in +257 -0
- data/ext/zlib-1.2.5/adler32.c +169 -0
- data/ext/zlib-1.2.5/compress.c +80 -0
- data/ext/zlib-1.2.5/configure +596 -0
- data/ext/zlib-1.2.5/crc32.c +442 -0
- data/ext/zlib-1.2.5/crc32.h +441 -0
- data/ext/zlib-1.2.5/deflate.c +1834 -0
- data/ext/zlib-1.2.5/deflate.h +342 -0
- data/ext/zlib-1.2.5/example.c +565 -0
- data/ext/zlib-1.2.5/gzclose.c +25 -0
- data/ext/zlib-1.2.5/gzguts.h +132 -0
- data/ext/zlib-1.2.5/gzlib.c +537 -0
- data/ext/zlib-1.2.5/gzread.c +653 -0
- data/ext/zlib-1.2.5/gzwrite.c +531 -0
- data/ext/zlib-1.2.5/infback.c +632 -0
- data/ext/zlib-1.2.5/inffast.c +340 -0
- data/ext/zlib-1.2.5/inffast.h +11 -0
- data/ext/zlib-1.2.5/inffixed.h +94 -0
- data/ext/zlib-1.2.5/inflate.c +1480 -0
- data/ext/zlib-1.2.5/inflate.h +122 -0
- data/ext/zlib-1.2.5/inftrees.c +330 -0
- data/ext/zlib-1.2.5/inftrees.h +62 -0
- data/ext/zlib-1.2.5/minigzip.c +440 -0
- data/ext/zlib-1.2.5/trees.c +1244 -0
- data/ext/zlib-1.2.5/trees.h +128 -0
- data/ext/zlib-1.2.5/uncompr.c +59 -0
- data/ext/zlib-1.2.5/zconf.h +428 -0
- data/ext/zlib-1.2.5/zlib.h +1613 -0
- data/ext/zlib-1.2.5/zutil.c +318 -0
- data/ext/zlib-1.2.5/zutil.h +274 -0
- metadata +211 -0
|
@@ -0,0 +1,453 @@
|
|
|
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
|
+
|
|
26
|
+
#include "archive_platform.h"
|
|
27
|
+
__FBSDID("$FreeBSD: head/lib/libarchive/archive_string.c 201095 2009-12-28 02:33:22Z kientzle $");
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* Basic resizable string support, to simplify manipulating arbitrary-sized
|
|
31
|
+
* strings while minimizing heap activity.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
#ifdef HAVE_STDLIB_H
|
|
35
|
+
#include <stdlib.h>
|
|
36
|
+
#endif
|
|
37
|
+
#ifdef HAVE_STRING_H
|
|
38
|
+
#include <string.h>
|
|
39
|
+
#endif
|
|
40
|
+
#ifdef HAVE_WCHAR_H
|
|
41
|
+
#include <wchar.h>
|
|
42
|
+
#endif
|
|
43
|
+
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
44
|
+
#include <windows.h>
|
|
45
|
+
#endif
|
|
46
|
+
|
|
47
|
+
#include "archive_private.h"
|
|
48
|
+
#include "archive_string.h"
|
|
49
|
+
|
|
50
|
+
struct archive_string *
|
|
51
|
+
__archive_string_append(struct archive_string *as, const char *p, size_t s)
|
|
52
|
+
{
|
|
53
|
+
if (__archive_string_ensure(as, as->length + s + 1) == NULL)
|
|
54
|
+
__archive_errx(1, "Out of memory");
|
|
55
|
+
memcpy(as->s + as->length, p, s);
|
|
56
|
+
as->s[as->length + s] = 0;
|
|
57
|
+
as->length += s;
|
|
58
|
+
return (as);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
void
|
|
62
|
+
__archive_string_copy(struct archive_string *dest, struct archive_string *src)
|
|
63
|
+
{
|
|
64
|
+
if (src->length == 0)
|
|
65
|
+
dest->length = 0;
|
|
66
|
+
else {
|
|
67
|
+
if (__archive_string_ensure(dest, src->length + 1) == NULL)
|
|
68
|
+
__archive_errx(1, "Out of memory");
|
|
69
|
+
memcpy(dest->s, src->s, src->length);
|
|
70
|
+
dest->length = src->length;
|
|
71
|
+
dest->s[dest->length] = 0;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
void
|
|
76
|
+
__archive_string_concat(struct archive_string *dest, struct archive_string *src)
|
|
77
|
+
{
|
|
78
|
+
if (src->length > 0) {
|
|
79
|
+
if (__archive_string_ensure(dest, dest->length + src->length + 1) == NULL)
|
|
80
|
+
__archive_errx(1, "Out of memory");
|
|
81
|
+
memcpy(dest->s + dest->length, src->s, src->length);
|
|
82
|
+
dest->length += src->length;
|
|
83
|
+
dest->s[dest->length] = 0;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
void
|
|
88
|
+
__archive_string_free(struct archive_string *as)
|
|
89
|
+
{
|
|
90
|
+
as->length = 0;
|
|
91
|
+
as->buffer_length = 0;
|
|
92
|
+
if (as->s != NULL) {
|
|
93
|
+
free(as->s);
|
|
94
|
+
as->s = NULL;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* Returns NULL on any allocation failure. */
|
|
99
|
+
struct archive_string *
|
|
100
|
+
__archive_string_ensure(struct archive_string *as, size_t s)
|
|
101
|
+
{
|
|
102
|
+
/* If buffer is already big enough, don't reallocate. */
|
|
103
|
+
if (as->s && (s <= as->buffer_length))
|
|
104
|
+
return (as);
|
|
105
|
+
|
|
106
|
+
/*
|
|
107
|
+
* Growing the buffer at least exponentially ensures that
|
|
108
|
+
* append operations are always linear in the number of
|
|
109
|
+
* characters appended. Using a smaller growth rate for
|
|
110
|
+
* larger buffers reduces memory waste somewhat at the cost of
|
|
111
|
+
* a larger constant factor.
|
|
112
|
+
*/
|
|
113
|
+
if (as->buffer_length < 32)
|
|
114
|
+
/* Start with a minimum 32-character buffer. */
|
|
115
|
+
as->buffer_length = 32;
|
|
116
|
+
else if (as->buffer_length < 8192)
|
|
117
|
+
/* Buffers under 8k are doubled for speed. */
|
|
118
|
+
as->buffer_length += as->buffer_length;
|
|
119
|
+
else {
|
|
120
|
+
/* Buffers 8k and over grow by at least 25% each time. */
|
|
121
|
+
size_t old_length = as->buffer_length;
|
|
122
|
+
as->buffer_length += as->buffer_length / 4;
|
|
123
|
+
/* Be safe: If size wraps, release buffer and return NULL. */
|
|
124
|
+
if (as->buffer_length < old_length) {
|
|
125
|
+
free(as->s);
|
|
126
|
+
as->s = NULL;
|
|
127
|
+
return (NULL);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/*
|
|
131
|
+
* The computation above is a lower limit to how much we'll
|
|
132
|
+
* grow the buffer. In any case, we have to grow it enough to
|
|
133
|
+
* hold the request.
|
|
134
|
+
*/
|
|
135
|
+
if (as->buffer_length < s)
|
|
136
|
+
as->buffer_length = s;
|
|
137
|
+
/* Now we can reallocate the buffer. */
|
|
138
|
+
as->s = (char *)realloc(as->s, as->buffer_length);
|
|
139
|
+
if (as->s == NULL)
|
|
140
|
+
return (NULL);
|
|
141
|
+
return (as);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
struct archive_string *
|
|
145
|
+
__archive_strncat(struct archive_string *as, const void *_p, size_t n)
|
|
146
|
+
{
|
|
147
|
+
size_t s;
|
|
148
|
+
const char *p, *pp;
|
|
149
|
+
|
|
150
|
+
p = (const char *)_p;
|
|
151
|
+
|
|
152
|
+
/* Like strlen(p), except won't examine positions beyond p[n]. */
|
|
153
|
+
s = 0;
|
|
154
|
+
pp = p;
|
|
155
|
+
while (*pp && s < n) {
|
|
156
|
+
pp++;
|
|
157
|
+
s++;
|
|
158
|
+
}
|
|
159
|
+
return (__archive_string_append(as, p, s));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
struct archive_string *
|
|
163
|
+
__archive_strappend_char(struct archive_string *as, char c)
|
|
164
|
+
{
|
|
165
|
+
return (__archive_string_append(as, &c, 1));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/*
|
|
169
|
+
* Translates a wide character string into UTF-8 and appends
|
|
170
|
+
* to the archive_string. Note: returns NULL if conversion fails,
|
|
171
|
+
* but still leaves a best-effort conversion in the argument as.
|
|
172
|
+
*/
|
|
173
|
+
struct archive_string *
|
|
174
|
+
__archive_strappend_w_utf8(struct archive_string *as, const wchar_t *w)
|
|
175
|
+
{
|
|
176
|
+
char *p;
|
|
177
|
+
unsigned wc;
|
|
178
|
+
char buff[256];
|
|
179
|
+
struct archive_string *return_val = as;
|
|
180
|
+
|
|
181
|
+
/*
|
|
182
|
+
* Convert one wide char at a time into 'buff', whenever that
|
|
183
|
+
* fills, append it to the string.
|
|
184
|
+
*/
|
|
185
|
+
p = buff;
|
|
186
|
+
while (*w != L'\0') {
|
|
187
|
+
/* Flush the buffer when we have <=16 bytes free. */
|
|
188
|
+
/* (No encoding has a single character >16 bytes.) */
|
|
189
|
+
if ((size_t)(p - buff) >= (size_t)(sizeof(buff) - 16)) {
|
|
190
|
+
*p = '\0';
|
|
191
|
+
archive_strcat(as, buff);
|
|
192
|
+
p = buff;
|
|
193
|
+
}
|
|
194
|
+
wc = *w++;
|
|
195
|
+
/* If this is a surrogate pair, assemble the full code point.*/
|
|
196
|
+
/* Note: wc must not be wchar_t here, because the full code
|
|
197
|
+
* point can be more than 16 bits! */
|
|
198
|
+
if (wc >= 0xD800 && wc <= 0xDBff
|
|
199
|
+
&& *w >= 0xDC00 && *w <= 0xDFFF) {
|
|
200
|
+
wc -= 0xD800;
|
|
201
|
+
wc *= 0x400;
|
|
202
|
+
wc += (*w - 0xDC00);
|
|
203
|
+
wc += 0x10000;
|
|
204
|
+
++w;
|
|
205
|
+
}
|
|
206
|
+
/* Translate code point to UTF8 */
|
|
207
|
+
if (wc <= 0x7f) {
|
|
208
|
+
*p++ = (char)wc;
|
|
209
|
+
} else if (wc <= 0x7ff) {
|
|
210
|
+
*p++ = 0xc0 | ((wc >> 6) & 0x1f);
|
|
211
|
+
*p++ = 0x80 | (wc & 0x3f);
|
|
212
|
+
} else if (wc <= 0xffff) {
|
|
213
|
+
*p++ = 0xe0 | ((wc >> 12) & 0x0f);
|
|
214
|
+
*p++ = 0x80 | ((wc >> 6) & 0x3f);
|
|
215
|
+
*p++ = 0x80 | (wc & 0x3f);
|
|
216
|
+
} else if (wc <= 0x1fffff) {
|
|
217
|
+
*p++ = 0xf0 | ((wc >> 18) & 0x07);
|
|
218
|
+
*p++ = 0x80 | ((wc >> 12) & 0x3f);
|
|
219
|
+
*p++ = 0x80 | ((wc >> 6) & 0x3f);
|
|
220
|
+
*p++ = 0x80 | (wc & 0x3f);
|
|
221
|
+
} else {
|
|
222
|
+
/* Unicode has no codes larger than 0x1fffff. */
|
|
223
|
+
/* TODO: use \uXXXX escape here instead of ? */
|
|
224
|
+
*p++ = '?';
|
|
225
|
+
return_val = NULL;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
*p = '\0';
|
|
229
|
+
archive_strcat(as, buff);
|
|
230
|
+
return (return_val);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
static int
|
|
234
|
+
utf8_to_unicode(int *pwc, const char *s, size_t n)
|
|
235
|
+
{
|
|
236
|
+
int ch;
|
|
237
|
+
|
|
238
|
+
/*
|
|
239
|
+
* Decode 1-4 bytes depending on the value of the first byte.
|
|
240
|
+
*/
|
|
241
|
+
ch = (unsigned char)*s;
|
|
242
|
+
if (ch == 0) {
|
|
243
|
+
return (0); /* Standard: return 0 for end-of-string. */
|
|
244
|
+
}
|
|
245
|
+
if ((ch & 0x80) == 0) {
|
|
246
|
+
*pwc = ch & 0x7f;
|
|
247
|
+
return (1);
|
|
248
|
+
}
|
|
249
|
+
if ((ch & 0xe0) == 0xc0) {
|
|
250
|
+
if (n < 2)
|
|
251
|
+
return (-1);
|
|
252
|
+
if ((s[1] & 0xc0) != 0x80) return (-1);
|
|
253
|
+
*pwc = ((ch & 0x1f) << 6) | (s[1] & 0x3f);
|
|
254
|
+
return (2);
|
|
255
|
+
}
|
|
256
|
+
if ((ch & 0xf0) == 0xe0) {
|
|
257
|
+
if (n < 3)
|
|
258
|
+
return (-1);
|
|
259
|
+
if ((s[1] & 0xc0) != 0x80) return (-1);
|
|
260
|
+
if ((s[2] & 0xc0) != 0x80) return (-1);
|
|
261
|
+
*pwc = ((ch & 0x0f) << 12)
|
|
262
|
+
| ((s[1] & 0x3f) << 6)
|
|
263
|
+
| (s[2] & 0x3f);
|
|
264
|
+
return (3);
|
|
265
|
+
}
|
|
266
|
+
if ((ch & 0xf8) == 0xf0) {
|
|
267
|
+
if (n < 4)
|
|
268
|
+
return (-1);
|
|
269
|
+
if ((s[1] & 0xc0) != 0x80) return (-1);
|
|
270
|
+
if ((s[2] & 0xc0) != 0x80) return (-1);
|
|
271
|
+
if ((s[3] & 0xc0) != 0x80) return (-1);
|
|
272
|
+
*pwc = ((ch & 0x07) << 18)
|
|
273
|
+
| ((s[1] & 0x3f) << 12)
|
|
274
|
+
| ((s[2] & 0x3f) << 6)
|
|
275
|
+
| (s[3] & 0x3f);
|
|
276
|
+
return (4);
|
|
277
|
+
}
|
|
278
|
+
/* Invalid first byte. */
|
|
279
|
+
return (-1);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/*
|
|
283
|
+
* Return a wide-character Unicode string by converting this archive_string
|
|
284
|
+
* from UTF-8. We assume that systems with 16-bit wchar_t always use
|
|
285
|
+
* UTF16 and systems with 32-bit wchar_t can accept UCS4.
|
|
286
|
+
*/
|
|
287
|
+
wchar_t *
|
|
288
|
+
__archive_string_utf8_w(struct archive_string *as)
|
|
289
|
+
{
|
|
290
|
+
wchar_t *ws, *dest;
|
|
291
|
+
int wc, wc2;/* Must be large enough for a 21-bit Unicode code point. */
|
|
292
|
+
const char *src;
|
|
293
|
+
int n;
|
|
294
|
+
|
|
295
|
+
ws = (wchar_t *)malloc((as->length + 1) * sizeof(wchar_t));
|
|
296
|
+
if (ws == NULL)
|
|
297
|
+
__archive_errx(1, "Out of memory");
|
|
298
|
+
dest = ws;
|
|
299
|
+
src = as->s;
|
|
300
|
+
while (*src != '\0') {
|
|
301
|
+
n = utf8_to_unicode(&wc, src, 8);
|
|
302
|
+
if (n == 0)
|
|
303
|
+
break;
|
|
304
|
+
if (n < 0) {
|
|
305
|
+
free(ws);
|
|
306
|
+
return (NULL);
|
|
307
|
+
}
|
|
308
|
+
src += n;
|
|
309
|
+
if (wc >= 0xDC00 && wc <= 0xDBFF) {
|
|
310
|
+
/* This is a leading surrogate; some idiot
|
|
311
|
+
* has translated UTF16 to UTF8 without combining
|
|
312
|
+
* surrogates; rebuild the full code point before
|
|
313
|
+
* continuing. */
|
|
314
|
+
n = utf8_to_unicode(&wc2, src, 8);
|
|
315
|
+
if (n < 0) {
|
|
316
|
+
free(ws);
|
|
317
|
+
return (NULL);
|
|
318
|
+
}
|
|
319
|
+
if (n == 0) /* Ignore the leading surrogate */
|
|
320
|
+
break;
|
|
321
|
+
if (wc2 < 0xDC00 || wc2 > 0xDFFF) {
|
|
322
|
+
/* If the second character isn't a
|
|
323
|
+
* trailing surrogate, then someone
|
|
324
|
+
* has really screwed up and this is
|
|
325
|
+
* invalid. */
|
|
326
|
+
free(ws);
|
|
327
|
+
return (NULL);
|
|
328
|
+
} else {
|
|
329
|
+
src += n;
|
|
330
|
+
wc -= 0xD800;
|
|
331
|
+
wc *= 0x400;
|
|
332
|
+
wc += wc2 - 0xDC00;
|
|
333
|
+
wc += 0x10000;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if ((sizeof(wchar_t) < 4) && (wc > 0xffff)) {
|
|
337
|
+
/* We have a code point that won't fit into a
|
|
338
|
+
* wchar_t; convert it to a surrogate pair. */
|
|
339
|
+
wc -= 0x10000;
|
|
340
|
+
*dest++ = ((wc >> 10) & 0x3ff) + 0xD800;
|
|
341
|
+
*dest++ = (wc & 0x3ff) + 0xDC00;
|
|
342
|
+
} else
|
|
343
|
+
*dest++ = wc;
|
|
344
|
+
}
|
|
345
|
+
*dest = L'\0';
|
|
346
|
+
return (ws);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
350
|
+
|
|
351
|
+
/*
|
|
352
|
+
* Translates a wide character string into current locale character set
|
|
353
|
+
* and appends to the archive_string. Note: returns NULL if conversion
|
|
354
|
+
* fails.
|
|
355
|
+
*
|
|
356
|
+
* Win32 builds use WideCharToMultiByte from the Windows API.
|
|
357
|
+
* (Maybe Cygwin should too? WideCharToMultiByte will know a
|
|
358
|
+
* lot more about local character encodings than the wcrtomb()
|
|
359
|
+
* wrapper is going to know.)
|
|
360
|
+
*/
|
|
361
|
+
struct archive_string *
|
|
362
|
+
__archive_strappend_w_mbs(struct archive_string *as, const wchar_t *w)
|
|
363
|
+
{
|
|
364
|
+
char *p;
|
|
365
|
+
int l, wl;
|
|
366
|
+
BOOL useDefaultChar = FALSE;
|
|
367
|
+
|
|
368
|
+
wl = (int)wcslen(w);
|
|
369
|
+
l = wl * 4 + 4;
|
|
370
|
+
p = malloc(l);
|
|
371
|
+
if (p == NULL)
|
|
372
|
+
__archive_errx(1, "Out of memory");
|
|
373
|
+
/* To check a useDefaultChar is to simulate error handling of
|
|
374
|
+
* the my_wcstombs() which is running on non Windows system with
|
|
375
|
+
* wctomb().
|
|
376
|
+
* And to set NULL for last argument is necessary when a codepage
|
|
377
|
+
* is not CP_ACP(current locale).
|
|
378
|
+
*/
|
|
379
|
+
l = WideCharToMultiByte(CP_ACP, 0, w, wl, p, l, NULL, &useDefaultChar);
|
|
380
|
+
if (l == 0) {
|
|
381
|
+
free(p);
|
|
382
|
+
return (NULL);
|
|
383
|
+
}
|
|
384
|
+
__archive_string_append(as, p, l);
|
|
385
|
+
free(p);
|
|
386
|
+
return (as);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
#else
|
|
390
|
+
|
|
391
|
+
/*
|
|
392
|
+
* Translates a wide character string into current locale character set
|
|
393
|
+
* and appends to the archive_string. Note: returns NULL if conversion
|
|
394
|
+
* fails.
|
|
395
|
+
*
|
|
396
|
+
* Non-Windows uses ISO C wcrtomb() or wctomb() to perform the conversion
|
|
397
|
+
* one character at a time. If a non-Windows platform doesn't have
|
|
398
|
+
* either of these, fall back to the built-in UTF8 conversion.
|
|
399
|
+
*/
|
|
400
|
+
struct archive_string *
|
|
401
|
+
__archive_strappend_w_mbs(struct archive_string *as, const wchar_t *w)
|
|
402
|
+
{
|
|
403
|
+
#if !defined(HAVE_WCTOMB) && !defined(HAVE_WCRTOMB)
|
|
404
|
+
/* If there's no built-in locale support, fall back to UTF8 always. */
|
|
405
|
+
return __archive_strappend_w_utf8(as, w);
|
|
406
|
+
#else
|
|
407
|
+
/* We cannot use the standard wcstombs() here because it
|
|
408
|
+
* cannot tell us how big the output buffer should be. So
|
|
409
|
+
* I've built a loop around wcrtomb() or wctomb() that
|
|
410
|
+
* converts a character at a time and resizes the string as
|
|
411
|
+
* needed. We prefer wcrtomb() when it's available because
|
|
412
|
+
* it's thread-safe. */
|
|
413
|
+
int n;
|
|
414
|
+
char *p;
|
|
415
|
+
char buff[256];
|
|
416
|
+
#if HAVE_WCRTOMB
|
|
417
|
+
mbstate_t shift_state;
|
|
418
|
+
|
|
419
|
+
memset(&shift_state, 0, sizeof(shift_state));
|
|
420
|
+
#else
|
|
421
|
+
/* Clear the shift state before starting. */
|
|
422
|
+
wctomb(NULL, L'\0');
|
|
423
|
+
#endif
|
|
424
|
+
|
|
425
|
+
/*
|
|
426
|
+
* Convert one wide char at a time into 'buff', whenever that
|
|
427
|
+
* fills, append it to the string.
|
|
428
|
+
*/
|
|
429
|
+
p = buff;
|
|
430
|
+
while (*w != L'\0') {
|
|
431
|
+
/* Flush the buffer when we have <=16 bytes free. */
|
|
432
|
+
/* (No encoding has a single character >16 bytes.) */
|
|
433
|
+
if ((size_t)(p - buff) >= (size_t)(sizeof(buff) - MB_CUR_MAX)) {
|
|
434
|
+
*p = '\0';
|
|
435
|
+
archive_strcat(as, buff);
|
|
436
|
+
p = buff;
|
|
437
|
+
}
|
|
438
|
+
#if HAVE_WCRTOMB
|
|
439
|
+
n = wcrtomb(p, *w++, &shift_state);
|
|
440
|
+
#else
|
|
441
|
+
n = wctomb(p, *w++);
|
|
442
|
+
#endif
|
|
443
|
+
if (n == -1)
|
|
444
|
+
return (NULL);
|
|
445
|
+
p += n;
|
|
446
|
+
}
|
|
447
|
+
*p = '\0';
|
|
448
|
+
archive_strcat(as, buff);
|
|
449
|
+
return (as);
|
|
450
|
+
#endif
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
#endif /* _WIN32 && ! __CYGWIN__ */
|
|
@@ -0,0 +1,148 @@
|
|
|
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_string.h 201092 2009-12-28 02:26:06Z kientzle $
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
#ifndef __LIBARCHIVE_BUILD
|
|
30
|
+
#error This header is only to be used internally to libarchive.
|
|
31
|
+
#endif
|
|
32
|
+
|
|
33
|
+
#ifndef ARCHIVE_STRING_H_INCLUDED
|
|
34
|
+
#define ARCHIVE_STRING_H_INCLUDED
|
|
35
|
+
|
|
36
|
+
#include <stdarg.h>
|
|
37
|
+
#ifdef HAVE_STDLIB_H
|
|
38
|
+
#include <stdlib.h> /* required for wchar_t on some systems */
|
|
39
|
+
#endif
|
|
40
|
+
#ifdef HAVE_STRING_H
|
|
41
|
+
#include <string.h>
|
|
42
|
+
#endif
|
|
43
|
+
#ifdef HAVE_WCHAR_H
|
|
44
|
+
#include <wchar.h>
|
|
45
|
+
#endif
|
|
46
|
+
|
|
47
|
+
/*
|
|
48
|
+
* Basic resizable/reusable string support a la Java's "StringBuffer."
|
|
49
|
+
*
|
|
50
|
+
* Unlike sbuf(9), the buffers here are fully reusable and track the
|
|
51
|
+
* length throughout.
|
|
52
|
+
*
|
|
53
|
+
* Note that all visible symbols here begin with "__archive" as they
|
|
54
|
+
* are internal symbols not intended for anyone outside of this library
|
|
55
|
+
* to see or use.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
struct archive_string {
|
|
59
|
+
char *s; /* Pointer to the storage */
|
|
60
|
+
size_t length; /* Length of 's' */
|
|
61
|
+
size_t buffer_length; /* Length of malloc-ed storage */
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/* Initialize an archive_string object on the stack or elsewhere. */
|
|
65
|
+
#define archive_string_init(a) \
|
|
66
|
+
do { (a)->s = NULL; (a)->length = 0; (a)->buffer_length = 0; } while(0)
|
|
67
|
+
|
|
68
|
+
/* Append a C char to an archive_string, resizing as necessary. */
|
|
69
|
+
struct archive_string *
|
|
70
|
+
__archive_strappend_char(struct archive_string *, char);
|
|
71
|
+
#define archive_strappend_char __archive_strappend_char
|
|
72
|
+
|
|
73
|
+
/* Convert a wide-char string to UTF-8 and append the result. */
|
|
74
|
+
struct archive_string *
|
|
75
|
+
__archive_strappend_w_utf8(struct archive_string *, const wchar_t *);
|
|
76
|
+
#define archive_strappend_w_utf8 __archive_strappend_w_utf8
|
|
77
|
+
|
|
78
|
+
/* Convert a wide-char string to current locale and append the result. */
|
|
79
|
+
/* Returns NULL if conversion fails. */
|
|
80
|
+
struct archive_string *
|
|
81
|
+
__archive_strappend_w_mbs(struct archive_string *, const wchar_t *);
|
|
82
|
+
#define archive_strappend_w_mbs __archive_strappend_w_mbs
|
|
83
|
+
|
|
84
|
+
/* Basic append operation. */
|
|
85
|
+
struct archive_string *
|
|
86
|
+
__archive_string_append(struct archive_string *as, const char *p, size_t s);
|
|
87
|
+
|
|
88
|
+
/* Copy one archive_string to another */
|
|
89
|
+
void
|
|
90
|
+
__archive_string_copy(struct archive_string *dest, struct archive_string *src);
|
|
91
|
+
#define archive_string_copy(dest, src) \
|
|
92
|
+
__archive_string_copy(dest, src)
|
|
93
|
+
|
|
94
|
+
/* Concatenate one archive_string to another */
|
|
95
|
+
void
|
|
96
|
+
__archive_string_concat(struct archive_string *dest, struct archive_string *src);
|
|
97
|
+
#define archive_string_concat(dest, src) \
|
|
98
|
+
__archive_string_concat(dest, src)
|
|
99
|
+
|
|
100
|
+
/* Ensure that the underlying buffer is at least as large as the request. */
|
|
101
|
+
struct archive_string *
|
|
102
|
+
__archive_string_ensure(struct archive_string *, size_t);
|
|
103
|
+
#define archive_string_ensure __archive_string_ensure
|
|
104
|
+
|
|
105
|
+
/* Append C string, which may lack trailing \0. */
|
|
106
|
+
/* The source is declared void * here because this gets used with
|
|
107
|
+
* "signed char *", "unsigned char *" and "char *" arguments.
|
|
108
|
+
* Declaring it "char *" as with some of the other functions just
|
|
109
|
+
* leads to a lot of extra casts. */
|
|
110
|
+
struct archive_string *
|
|
111
|
+
__archive_strncat(struct archive_string *, const void *, size_t);
|
|
112
|
+
#define archive_strncat __archive_strncat
|
|
113
|
+
|
|
114
|
+
/* Append a C string to an archive_string, resizing as necessary. */
|
|
115
|
+
#define archive_strcat(as,p) __archive_string_append((as),(p),strlen(p))
|
|
116
|
+
|
|
117
|
+
/* Copy a C string to an archive_string, resizing as necessary. */
|
|
118
|
+
#define archive_strcpy(as,p) \
|
|
119
|
+
((as)->length = 0, __archive_string_append((as), (p), p == NULL ? 0 : strlen(p)))
|
|
120
|
+
|
|
121
|
+
/* Copy a C string to an archive_string with limit, resizing as necessary. */
|
|
122
|
+
#define archive_strncpy(as,p,l) \
|
|
123
|
+
((as)->length=0, archive_strncat((as), (p), (l)))
|
|
124
|
+
|
|
125
|
+
/* Return length of string. */
|
|
126
|
+
#define archive_strlen(a) ((a)->length)
|
|
127
|
+
|
|
128
|
+
/* Set string length to zero. */
|
|
129
|
+
#define archive_string_empty(a) ((a)->length = 0)
|
|
130
|
+
|
|
131
|
+
/* Release any allocated storage resources. */
|
|
132
|
+
void __archive_string_free(struct archive_string *);
|
|
133
|
+
#define archive_string_free __archive_string_free
|
|
134
|
+
|
|
135
|
+
/* Like 'vsprintf', but resizes the underlying string as necessary. */
|
|
136
|
+
void __archive_string_vsprintf(struct archive_string *, const char *,
|
|
137
|
+
va_list);
|
|
138
|
+
#define archive_string_vsprintf __archive_string_vsprintf
|
|
139
|
+
|
|
140
|
+
void __archive_string_sprintf(struct archive_string *, const char *, ...);
|
|
141
|
+
#define archive_string_sprintf __archive_string_sprintf
|
|
142
|
+
|
|
143
|
+
/* Allocates a fresh buffer and converts as (assumed to be UTF-8) into it.
|
|
144
|
+
* Returns NULL if conversion failed in any way. */
|
|
145
|
+
wchar_t *__archive_string_utf8_w(struct archive_string *as);
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
#endif
|