1 /*- 2 * Copyright (c) 2009-2012,2014 Michihiro NAKAJIMA 3 * Copyright (c) 2003-2007 Tim Kientzle 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 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. 14 * 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. 25 */ 26 27 #include "archive_platform.h" 28 29 #ifdef HAVE_STDLIB_H 30 #include <stdlib.h> 31 #endif 32 #ifdef HAVE_STRING_H 33 #include <string.h> 34 #endif 35 #ifdef HAVE_ZLIB_H 36 #include <zlib.h> 37 #endif 38 #ifdef HAVE_LZMA_H 39 #include <lzma.h> 40 #endif 41 #ifdef HAVE_BZLIB_H 42 #include <bzlib.h> 43 #endif 44 #ifdef HAVE_LZ4_H 45 #include <lz4.h> 46 #endif 47 #ifdef HAVE_ZSTD_H 48 #include <zstd.h> 49 #endif 50 51 #include "archive.h" 52 #include "archive_private.h" 53 #include "archive_string.h" 54 55 const char * 56 archive_version_details(void) 57 { 58 static struct archive_string str; 59 static int init = 0; 60 const char *zlib = archive_zlib_version(); 61 const char *liblzma = archive_liblzma_version(); 62 const char *bzlib = archive_bzlib_version(); 63 const char *liblz4 = archive_liblz4_version(); 64 const char *libzstd = archive_libzstd_version(); 65 66 if (!init) { 67 archive_string_init(&str); 68 69 archive_strcat(&str, ARCHIVE_VERSION_STRING); 70 if (zlib != NULL) { 71 archive_strcat(&str, " zlib/"); 72 archive_strcat(&str, zlib); 73 } 74 if (liblzma) { 75 archive_strcat(&str, " liblzma/"); 76 archive_strcat(&str, liblzma); 77 } 78 if (bzlib) { 79 const char *p = bzlib; 80 const char *sep = strchr(p, ','); 81 if (sep == NULL) 82 sep = p + strlen(p); 83 archive_strcat(&str, " bz2lib/"); 84 archive_strncat(&str, p, sep - p); 85 } 86 if (liblz4) { 87 archive_strcat(&str, " liblz4/"); 88 archive_strcat(&str, liblz4); 89 } 90 if (libzstd) { 91 archive_strcat(&str, " libzstd/"); 92 archive_strcat(&str, libzstd); 93 } 94 } 95 return str.s; 96 } 97 98 const char * 99 archive_zlib_version(void) 100 { 101 #ifdef HAVE_ZLIB_H 102 return ZLIB_VERSION; 103 #else 104 return NULL; 105 #endif 106 } 107 108 const char * 109 archive_liblzma_version(void) 110 { 111 #ifdef HAVE_LZMA_H 112 return LZMA_VERSION_STRING; 113 #else 114 return NULL; 115 #endif 116 } 117 118 const char * 119 archive_bzlib_version(void) 120 { 121 #ifdef HAVE_BZLIB_H 122 return BZ2_bzlibVersion(); 123 #else 124 return NULL; 125 #endif 126 } 127 128 const char * 129 archive_liblz4_version(void) 130 { 131 #if defined(HAVE_LZ4_H) && defined(HAVE_LIBLZ4) 132 #define str(s) #s 133 #define NUMBER(x) str(x) 134 return NUMBER(LZ4_VERSION_MAJOR) "." NUMBER(LZ4_VERSION_MINOR) "." NUMBER(LZ4_VERSION_RELEASE); 135 #undef NUMBER 136 #undef str 137 #else 138 return NULL; 139 #endif 140 } 141 142 const char * 143 archive_libzstd_version(void) 144 { 145 #if HAVE_ZSTD_H && HAVE_LIBZSTD 146 return ZSTD_VERSION_STRING; 147 #else 148 return NULL; 149 #endif 150 } 151