archive_version_details.c 3.6 KB

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