summaryrefslogtreecommitdiffstats
path: root/libarchive/archive_util.c
diff options
context:
space:
mode:
authorLibArchive Upstream <libarchive-discuss@googlegroups.com>2014-03-18 03:43:07 (GMT)
committerBrad King <brad.king@kitware.com>2014-04-03 18:19:12 (GMT)
commit64713ae3ffddf6fbbfa7ea762c3d756cb245a066 (patch)
tree74d1e4b730c28f4cf84bbb558dd337d3d1a3f178 /libarchive/archive_util.c
parent35df7c8ba8854e97bd6994c4d1143f57535ed6f2 (diff)
downloadCMake-64713ae3ffddf6fbbfa7ea762c3d756cb245a066.zip
CMake-64713ae3ffddf6fbbfa7ea762c3d756cb245a066.tar.gz
CMake-64713ae3ffddf6fbbfa7ea762c3d756cb245a066.tar.bz2
libarchive 3.1.2-218-g00f4bd83 (reduced)
Extract upstream libarchive using the following shell code. url=git://github.com/libarchive/libarchive.git && v=3.1.2-218-g00f4bd83 && r=00f4bd83 && paths=" CMakeLists.txt COPYING CTestConfig.cmake build/cmake build/pkgconfig build/utils build/version libarchive/*.* " && mkdir libarchive-$v-g$r-reduced && git clone $url libarchive-git && date=$(cd libarchive-git && git log -n 1 --format='%cd' $r) && (cd libarchive-git && git archive --format=tar $r -- $paths) | (cd libarchive-$v-g$r-reduced && tar xv) && fromdos libarchive-$v-g$r-reduced/build/cmake/Find*.cmake && echo "g$r date: $date"
Diffstat (limited to 'libarchive/archive_util.c')
-rw-r--r--libarchive/archive_util.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/libarchive/archive_util.c b/libarchive/archive_util.c
index 34d8081..3d92566 100644
--- a/libarchive/archive_util.c
+++ b/libarchive/archive_util.c
@@ -45,6 +45,15 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_util.c 201098 2009-12-28 02:58:1
#if defined(HAVE_WINCRYPT_H) && !defined(__CYGWIN__)
#include <wincrypt.h>
#endif
+#ifdef HAVE_ZLIB_H
+#include <zlib.h>
+#endif
+#ifdef HAVE_LZMA_H
+#include <lzma.h>
+#endif
+#ifdef HAVE_BZLIB_H
+#include <bzlib.h>
+#endif
#include "archive.h"
#include "archive_private.h"
@@ -54,6 +63,8 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_util.c 201098 2009-12-28 02:58:1
#define O_CLOEXEC 0
#endif
+static int archive_utility_string_sort_helper(char **, unsigned int);
+
/* Generic initialization of 'struct archive' objects. */
int
__archive_clean(struct archive *a)
@@ -74,6 +85,38 @@ archive_version_string(void)
return (ARCHIVE_VERSION_STRING);
}
+const char *
+archive_version_details(void)
+{
+ static struct archive_string str;
+ static int init = 0;
+
+ if (!init) {
+ archive_string_init(&str);
+
+ archive_strcat(&str, ARCHIVE_VERSION_STRING);
+#ifdef HAVE_ZLIB_H
+ archive_strcat(&str, " zlib/");
+ archive_strcat(&str, ZLIB_VERSION);
+#endif
+#ifdef HAVE_LZMA_H
+ archive_strcat(&str, " liblzma/");
+ archive_strcat(&str, LZMA_VERSION_STRING);
+#endif
+#ifdef HAVE_BZLIB_H
+ {
+ const char *p = BZ2_bzlibVersion();
+ const char *sep = strchr(p, ',');
+ if (sep == NULL)
+ sep = p + strlen(p);
+ archive_strcat(&str, " bz2lib/");
+ archive_strncat(&str, p, sep - p);
+ }
+#endif
+ }
+ return str.s;
+}
+
int
archive_errno(struct archive *a)
{
@@ -499,3 +542,69 @@ __archive_ensure_cloexec_flag(int fd)
}
#endif
}
+
+/*
+ * Utility function to sort a group of strings using quicksort.
+ */
+static int
+archive_utility_string_sort_helper(char **strings, unsigned int n)
+{
+ unsigned int i, lesser_count, greater_count;
+ char **lesser, **greater, **tmp, *pivot;
+ int retval1, retval2;
+
+ /* A list of 0 or 1 elements is already sorted */
+ if (n <= 1)
+ return (ARCHIVE_OK);
+
+ lesser_count = greater_count = 0;
+ lesser = greater = NULL;
+ pivot = strings[0];
+ for (i = 1; i < n; i++)
+ {
+ if (strcmp(strings[i], pivot) < 0)
+ {
+ lesser_count++;
+ tmp = (char **)realloc(lesser, lesser_count * sizeof(char *));
+ if (!tmp)
+ return (ARCHIVE_FATAL);
+ lesser = tmp;
+ lesser[lesser_count - 1] = strings[i];
+ }
+ else
+ {
+ greater_count++;
+ tmp = (char **)realloc(greater, greater_count * sizeof(char *));
+ if (!tmp)
+ return (ARCHIVE_FATAL);
+ greater = tmp;
+ greater[greater_count - 1] = strings[i];
+ }
+ }
+
+ /* quicksort(lesser) */
+ retval1 = archive_utility_string_sort_helper(lesser, lesser_count);
+ for (i = 0; i < lesser_count; i++)
+ strings[i] = lesser[i];
+ free(lesser);
+
+ /* pivot */
+ strings[lesser_count] = pivot;
+
+ /* quicksort(greater) */
+ retval2 = archive_utility_string_sort_helper(greater, greater_count);
+ for (i = 0; i < greater_count; i++)
+ strings[lesser_count + 1 + i] = greater[i];
+ free(greater);
+
+ return (retval1 < retval2) ? retval1 : retval2;
+}
+
+int
+archive_utility_string_sort(char **strings)
+{
+ unsigned int size = 0;
+ while (strings[size] != NULL)
+ size++;
+ return archive_utility_string_sort_helper(strings, size);
+}