Blame libarchive/archive_version_details.c

Packit 08bd4c
/*-
Packit 08bd4c
 * Copyright (c) 2009-2012,2014 Michihiro NAKAJIMA
Packit 08bd4c
 * Copyright (c) 2003-2007 Tim Kientzle
Packit 08bd4c
 * All rights reserved.
Packit 08bd4c
 *
Packit 08bd4c
 * Redistribution and use in source and binary forms, with or without
Packit 08bd4c
 * modification, are permitted provided that the following conditions
Packit 08bd4c
 * are met:
Packit 08bd4c
 * 1. Redistributions of source code must retain the above copyright
Packit 08bd4c
 *    notice, this list of conditions and the following disclaimer.
Packit 08bd4c
 * 2. Redistributions in binary form must reproduce the above copyright
Packit 08bd4c
 *    notice, this list of conditions and the following disclaimer in the
Packit 08bd4c
 *    documentation and/or other materials provided with the distribution.
Packit 08bd4c
 *
Packit 08bd4c
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
Packit 08bd4c
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Packit 08bd4c
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Packit 08bd4c
 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
Packit 08bd4c
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
Packit 08bd4c
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit 08bd4c
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit 08bd4c
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit 08bd4c
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
Packit 08bd4c
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 08bd4c
 */
Packit 08bd4c
Packit 08bd4c
#include "archive_platform.h"
Packit 08bd4c
__FBSDID("$FreeBSD: head/lib/libarchive/archive_util.c 201098 2009-12-28 02:58:14Z kientzle $");
Packit 08bd4c
Packit 08bd4c
#ifdef HAVE_STDLIB_H
Packit 08bd4c
#include <stdlib.h>
Packit 08bd4c
#endif
Packit 08bd4c
#ifdef HAVE_STRING_H
Packit 08bd4c
#include <string.h>
Packit 08bd4c
#endif
Packit 08bd4c
#ifdef HAVE_ZLIB_H
Packit 08bd4c
#include <zlib.h>
Packit 08bd4c
#endif
Packit 08bd4c
#ifdef HAVE_LZMA_H
Packit 08bd4c
#include <lzma.h>
Packit 08bd4c
#endif
Packit 08bd4c
#ifdef HAVE_BZLIB_H
Packit 08bd4c
#include <bzlib.h>
Packit 08bd4c
#endif
Packit 08bd4c
#ifdef HAVE_LZ4_H
Packit 08bd4c
#include <lz4.h>
Packit 08bd4c
#endif
Packit 08bd4c
Packit 08bd4c
#include "archive.h"
Packit 08bd4c
#include "archive_private.h"
Packit 08bd4c
#include "archive_string.h"
Packit 08bd4c
Packit 08bd4c
const char *
Packit 08bd4c
archive_version_details(void)
Packit 08bd4c
{
Packit 08bd4c
	static struct archive_string str;
Packit 08bd4c
	static int init = 0;
Packit 08bd4c
	const char *zlib = archive_zlib_version();
Packit 08bd4c
	const char *liblzma = archive_liblzma_version();
Packit 08bd4c
	const char *bzlib = archive_bzlib_version();
Packit 08bd4c
	const char *liblz4 = archive_liblz4_version();
Packit 08bd4c
Packit 08bd4c
	if (!init) {
Packit 08bd4c
		archive_string_init(&str);
Packit 08bd4c
Packit 08bd4c
		archive_strcat(&str, ARCHIVE_VERSION_STRING);
Packit 08bd4c
		if (zlib != NULL) {
Packit 08bd4c
			archive_strcat(&str, " zlib/");
Packit 08bd4c
			archive_strcat(&str, zlib);
Packit 08bd4c
		}
Packit 08bd4c
		if (liblzma) {
Packit 08bd4c
			archive_strcat(&str, " liblzma/");
Packit 08bd4c
			archive_strcat(&str, liblzma);
Packit 08bd4c
		}
Packit 08bd4c
		if (bzlib) {
Packit 08bd4c
			const char *p = bzlib;
Packit 08bd4c
			const char *sep = strchr(p, ',');
Packit 08bd4c
			if (sep == NULL)
Packit 08bd4c
				sep = p + strlen(p);
Packit 08bd4c
			archive_strcat(&str, " bz2lib/");
Packit 08bd4c
			archive_strncat(&str, p, sep - p);
Packit 08bd4c
		}
Packit 08bd4c
		if (liblz4) {
Packit 08bd4c
			archive_strcat(&str, " liblz4/");
Packit 08bd4c
			archive_strcat(&str, liblz4);
Packit 08bd4c
		}
Packit 08bd4c
	}
Packit 08bd4c
	return str.s;
Packit 08bd4c
}
Packit 08bd4c
Packit 08bd4c
const char *
Packit 08bd4c
archive_zlib_version(void)
Packit 08bd4c
{
Packit 08bd4c
#ifdef HAVE_ZLIB_H
Packit 08bd4c
	return ZLIB_VERSION;
Packit 08bd4c
#else
Packit 08bd4c
	return NULL;
Packit 08bd4c
#endif
Packit 08bd4c
}
Packit 08bd4c
Packit 08bd4c
const char *
Packit 08bd4c
archive_liblzma_version(void)
Packit 08bd4c
{
Packit 08bd4c
#ifdef HAVE_LZMA_H
Packit 08bd4c
	return LZMA_VERSION_STRING;
Packit 08bd4c
#else
Packit 08bd4c
	return NULL;
Packit 08bd4c
#endif
Packit 08bd4c
}
Packit 08bd4c
Packit 08bd4c
const char *
Packit 08bd4c
archive_bzlib_version(void)
Packit 08bd4c
{
Packit 08bd4c
#ifdef HAVE_BZLIB_H
Packit 08bd4c
	return BZ2_bzlibVersion();
Packit 08bd4c
#else
Packit 08bd4c
	return NULL;
Packit 08bd4c
#endif
Packit 08bd4c
}
Packit 08bd4c
Packit 08bd4c
const char *
Packit 08bd4c
archive_liblz4_version(void)
Packit 08bd4c
{
Packit 08bd4c
#if defined(HAVE_LZ4_H) && defined(HAVE_LIBLZ4)
Packit 08bd4c
#define str(s) #s
Packit 08bd4c
#define NUMBER(x) str(x)
Packit 08bd4c
	return NUMBER(LZ4_VERSION_MAJOR) "." NUMBER(LZ4_VERSION_MINOR) "." NUMBER(LZ4_VERSION_RELEASE);
Packit 08bd4c
#undef NUMBER
Packit 08bd4c
#undef str
Packit 08bd4c
#else
Packit 08bd4c
	return NULL;
Packit 08bd4c
#endif
Packit 08bd4c
}