archive_version_details.c revision 316337
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__FBSDID("$FreeBSD: stable/11/contrib/libarchive/libarchive/archive_version_details.c 316337 2017-03-31 20:16:24Z mm $"); 29 30#ifdef HAVE_STDLIB_H 31#include <stdlib.h> 32#endif 33#ifdef HAVE_STRING_H 34#include <string.h> 35#endif 36#ifdef HAVE_ZLIB_H 37#include <zlib.h> 38#endif 39#ifdef HAVE_LZMA_H 40#include <lzma.h> 41#endif 42#ifdef HAVE_BZLIB_H 43#include <bzlib.h> 44#endif 45#ifdef HAVE_LZ4_H 46#include <lz4.h> 47#endif 48 49#include "archive.h" 50#include "archive_private.h" 51#include "archive_string.h" 52 53const char * 54archive_version_details(void) 55{ 56 static struct archive_string str; 57 static int init = 0; 58 const char *zlib = archive_zlib_version(); 59 const char *liblzma = archive_liblzma_version(); 60 const char *bzlib = archive_bzlib_version(); 61 const char *liblz4 = archive_liblz4_version(); 62 63 if (!init) { 64 archive_string_init(&str); 65 66 archive_strcat(&str, ARCHIVE_VERSION_STRING); 67 if (zlib != NULL) { 68 archive_strcat(&str, " zlib/"); 69 archive_strcat(&str, zlib); 70 } 71 if (liblzma) { 72 archive_strcat(&str, " liblzma/"); 73 archive_strcat(&str, liblzma); 74 } 75 if (bzlib) { 76 const char *p = bzlib; 77 const char *sep = strchr(p, ','); 78 if (sep == NULL) 79 sep = p + strlen(p); 80 archive_strcat(&str, " bz2lib/"); 81 archive_strncat(&str, p, sep - p); 82 } 83 if (liblz4) { 84 archive_strcat(&str, " liblz4/"); 85 archive_strcat(&str, liblz4); 86 } 87 } 88 return str.s; 89} 90 91const char * 92archive_zlib_version(void) 93{ 94#ifdef HAVE_ZLIB_H 95 return ZLIB_VERSION; 96#else 97 return NULL; 98#endif 99} 100 101const char * 102archive_liblzma_version(void) 103{ 104#ifdef HAVE_LZMA_H 105 return LZMA_VERSION_STRING; 106#else 107 return NULL; 108#endif 109} 110 111const char * 112archive_bzlib_version(void) 113{ 114#ifdef HAVE_BZLIB_H 115 return BZ2_bzlibVersion(); 116#else 117 return NULL; 118#endif 119} 120 121const char * 122archive_liblz4_version(void) 123{ 124#if defined(HAVE_LZ4_H) && defined(HAVE_LIBLZ4) 125#define str(s) #s 126#define NUMBER(x) str(x) 127 return NUMBER(LZ4_VERSION_MAJOR) "." NUMBER(LZ4_VERSION_MINOR) "." NUMBER(LZ4_VERSION_RELEASE); 128#undef NUMBER 129#undef str 130#else 131 return NULL; 132#endif 133} 134