Blame libarchive/archive_write_set_format.c

Packit 08bd4c
/*-
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_write_set_format.c 201168 2009-12-29 06:15:32Z kientzle $");
Packit 08bd4c
Packit 08bd4c
#ifdef HAVE_SYS_TYPES_H
Packit 08bd4c
#include <sys/types.h>
Packit 08bd4c
#endif
Packit 08bd4c
Packit 08bd4c
#ifdef HAVE_ERRNO_H
Packit 08bd4c
#include <errno.h>
Packit 08bd4c
#endif
Packit 08bd4c
Packit 08bd4c
#include "archive.h"
Packit 08bd4c
#include "archive_private.h"
Packit 08bd4c
Packit 08bd4c
/* A table that maps format codes to functions. */
Packit 08bd4c
static const
Packit 08bd4c
struct { int code; int (*setter)(struct archive *); } codes[] =
Packit 08bd4c
{
Packit 08bd4c
	{ ARCHIVE_FORMAT_7ZIP,		archive_write_set_format_7zip },
Packit 08bd4c
	{ ARCHIVE_FORMAT_CPIO,		archive_write_set_format_cpio },
Packit 08bd4c
	{ ARCHIVE_FORMAT_CPIO_POSIX,	archive_write_set_format_cpio },
Packit 08bd4c
	{ ARCHIVE_FORMAT_CPIO_SVR4_NOCRC,	archive_write_set_format_cpio_newc },
Packit 08bd4c
	{ ARCHIVE_FORMAT_ISO9660,	archive_write_set_format_iso9660 },
Packit 08bd4c
	{ ARCHIVE_FORMAT_MTREE,		archive_write_set_format_mtree },
Packit 08bd4c
	{ ARCHIVE_FORMAT_RAW,		archive_write_set_format_raw },
Packit 08bd4c
	{ ARCHIVE_FORMAT_SHAR,		archive_write_set_format_shar },
Packit 08bd4c
	{ ARCHIVE_FORMAT_SHAR_BASE,	archive_write_set_format_shar },
Packit 08bd4c
	{ ARCHIVE_FORMAT_SHAR_DUMP,	archive_write_set_format_shar_dump },
Packit 08bd4c
	{ ARCHIVE_FORMAT_TAR,	archive_write_set_format_pax_restricted },
Packit 08bd4c
	{ ARCHIVE_FORMAT_TAR_GNUTAR,	archive_write_set_format_gnutar },
Packit 08bd4c
	{ ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE, archive_write_set_format_pax },
Packit 08bd4c
	{ ARCHIVE_FORMAT_TAR_PAX_RESTRICTED,
Packit 08bd4c
				archive_write_set_format_pax_restricted },
Packit 08bd4c
	{ ARCHIVE_FORMAT_TAR_USTAR,	archive_write_set_format_ustar },
Packit 08bd4c
	{ ARCHIVE_FORMAT_WARC,		archive_write_set_format_warc },
Packit 08bd4c
	{ ARCHIVE_FORMAT_XAR,		archive_write_set_format_xar },
Packit 08bd4c
	{ ARCHIVE_FORMAT_ZIP,		archive_write_set_format_zip },
Packit 08bd4c
	{ 0,		NULL }
Packit 08bd4c
};
Packit 08bd4c
Packit 08bd4c
int
Packit 08bd4c
archive_write_set_format(struct archive *a, int code)
Packit 08bd4c
{
Packit 08bd4c
	int i;
Packit 08bd4c
Packit 08bd4c
	for (i = 0; codes[i].code != 0; i++) {
Packit 08bd4c
		if (code == codes[i].code)
Packit 08bd4c
			return ((codes[i].setter)(a));
Packit 08bd4c
	}
Packit 08bd4c
Packit 08bd4c
	archive_set_error(a, EINVAL, "No such format");
Packit 08bd4c
	return (ARCHIVE_FATAL);
Packit 08bd4c
}