]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/libarchive/libarchive/archive_version_details.c
MFC r368207,368607:
[FreeBSD/stable/10.git] / contrib / libarchive / libarchive / archive_version_details.c
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$");
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 #ifdef HAVE_ZSTD_H
49 #include <zstd.h>
50 #endif
51
52 #include "archive.h"
53 #include "archive_private.h"
54 #include "archive_string.h"
55
56 const char *
57 archive_version_details(void)
58 {
59         static struct archive_string str;
60         static int init = 0;
61         const char *zlib = archive_zlib_version();
62         const char *liblzma = archive_liblzma_version();
63         const char *bzlib = archive_bzlib_version();
64         const char *liblz4 = archive_liblz4_version();
65         const char *libzstd = archive_libzstd_version();
66
67         if (!init) {
68                 archive_string_init(&str);
69
70                 archive_strcat(&str, ARCHIVE_VERSION_STRING);
71                 if (zlib != NULL) {
72                         archive_strcat(&str, " zlib/");
73                         archive_strcat(&str, zlib);
74                 }
75                 if (liblzma) {
76                         archive_strcat(&str, " liblzma/");
77                         archive_strcat(&str, liblzma);
78                 }
79                 if (bzlib) {
80                         const char *p = bzlib;
81                         const char *sep = strchr(p, ',');
82                         if (sep == NULL)
83                                 sep = p + strlen(p);
84                         archive_strcat(&str, " bz2lib/");
85                         archive_strncat(&str, p, sep - p);
86                 }
87                 if (liblz4) {
88                         archive_strcat(&str, " liblz4/");
89                         archive_strcat(&str, liblz4);
90                 }
91                 if (libzstd) {
92                         archive_strcat(&str, " libzstd/");
93                         archive_strcat(&str, libzstd);
94                 }
95         }
96         return str.s;
97 }
98
99 const char *
100 archive_zlib_version(void)
101 {
102 #ifdef HAVE_ZLIB_H
103         return ZLIB_VERSION;
104 #else
105         return NULL;
106 #endif
107 }
108
109 const char *
110 archive_liblzma_version(void)
111 {
112 #ifdef HAVE_LZMA_H
113         return LZMA_VERSION_STRING;
114 #else
115         return NULL;
116 #endif
117 }
118
119 const char *
120 archive_bzlib_version(void)
121 {
122 #ifdef HAVE_BZLIB_H
123         return BZ2_bzlibVersion();
124 #else
125         return NULL;
126 #endif
127 }
128
129 const char *
130 archive_liblz4_version(void)
131 {
132 #if defined(HAVE_LZ4_H) && defined(HAVE_LIBLZ4)
133 #define str(s) #s
134 #define NUMBER(x) str(x)
135         return NUMBER(LZ4_VERSION_MAJOR) "." NUMBER(LZ4_VERSION_MINOR) "." NUMBER(LZ4_VERSION_RELEASE);
136 #undef NUMBER
137 #undef str
138 #else
139         return NULL;
140 #endif
141 }
142
143 const char *
144 archive_libzstd_version(void)
145 {
146 #if HAVE_ZSTD_H && HAVE_LIBZSTD
147         return ZSTD_VERSION_STRING;
148 #else
149         return NULL;
150 #endif
151 }