archive_version_details.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #include "archive.h"
  47. #include "archive_private.h"
  48. #include "archive_string.h"
  49. const char *
  50. archive_version_details(void)
  51. {
  52. static struct archive_string str;
  53. static int init = 0;
  54. const char *zlib = archive_zlib_version();
  55. const char *liblzma = archive_liblzma_version();
  56. const char *bzlib = archive_bzlib_version();
  57. const char *liblz4 = archive_liblz4_version();
  58. if (!init) {
  59. archive_string_init(&str);
  60. archive_strcat(&str, ARCHIVE_VERSION_STRING);
  61. if (zlib != NULL) {
  62. archive_strcat(&str, " zlib/");
  63. archive_strcat(&str, zlib);
  64. }
  65. if (liblzma) {
  66. archive_strcat(&str, " liblzma/");
  67. archive_strcat(&str, liblzma);
  68. }
  69. if (bzlib) {
  70. const char *p = bzlib;
  71. const char *sep = strchr(p, ',');
  72. if (sep == NULL)
  73. sep = p + strlen(p);
  74. archive_strcat(&str, " bz2lib/");
  75. archive_strncat(&str, p, sep - p);
  76. }
  77. if (liblz4) {
  78. archive_strcat(&str, " liblz4/");
  79. archive_strcat(&str, liblz4);
  80. }
  81. }
  82. return str.s;
  83. }
  84. const char *
  85. archive_zlib_version(void)
  86. {
  87. #ifdef HAVE_ZLIB_H
  88. return ZLIB_VERSION;
  89. #else
  90. return NULL;
  91. #endif
  92. }
  93. const char *
  94. archive_liblzma_version(void)
  95. {
  96. #ifdef HAVE_LZMA_H
  97. return LZMA_VERSION_STRING;
  98. #else
  99. return NULL;
  100. #endif
  101. }
  102. const char *
  103. archive_bzlib_version(void)
  104. {
  105. #ifdef HAVE_BZLIB_H
  106. return BZ2_bzlibVersion();
  107. #else
  108. return NULL;
  109. #endif
  110. }
  111. const char *
  112. archive_liblz4_version(void)
  113. {
  114. #if defined(HAVE_LZ4_H) && defined(HAVE_LIBLZ4)
  115. #define str(s) #s
  116. #define NUMBER(x) str(x)
  117. return NUMBER(LZ4_VERSION_MAJOR) "." NUMBER(LZ4_VERSION_MINOR) "." NUMBER(LZ4_VERSION_RELEASE);
  118. #undef NUMBER
  119. #undef str
  120. #else
  121. return NULL;
  122. #endif
  123. }