1228753Smm/*-
2228753Smm * Copyright (c) 2003-2007 Tim Kientzle
3228753Smm * All rights reserved.
4228753Smm *
5228753Smm * Redistribution and use in source and binary forms, with or without
6228753Smm * modification, are permitted provided that the following conditions
7228753Smm * are met:
8228753Smm * 1. Redistributions of source code must retain the above copyright
9228753Smm *    notice, this list of conditions and the following disclaimer.
10228753Smm * 2. Redistributions in binary form must reproduce the above copyright
11228753Smm *    notice, this list of conditions and the following disclaimer in the
12228753Smm *    documentation and/or other materials provided with the distribution.
13228753Smm *
14228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24228753Smm */
25228753Smm
26228753Smm#include "archive_platform.h"
27229592Smm__FBSDID("$FreeBSD$");
28228753Smm
29228753Smm#ifdef HAVE_SYS_TYPES_H
30228753Smm#include <sys/types.h>
31228753Smm#endif
32228753Smm
33228753Smm#ifdef HAVE_ERRNO_H
34228753Smm#include <errno.h>
35228753Smm#endif
36228753Smm
37228753Smm#include "archive.h"
38228753Smm#include "archive_private.h"
39228753Smm
40228753Smm/* A table that maps format codes to functions. */
41228753Smmstatic
42228753Smmstruct { int code; int (*setter)(struct archive *); } codes[] =
43228753Smm{
44228753Smm	{ ARCHIVE_FORMAT_CPIO,		archive_write_set_format_cpio },
45228753Smm	{ ARCHIVE_FORMAT_CPIO_SVR4_NOCRC,	archive_write_set_format_cpio_newc },
46228753Smm	{ ARCHIVE_FORMAT_CPIO_POSIX,	archive_write_set_format_cpio },
47228753Smm	{ ARCHIVE_FORMAT_MTREE,		archive_write_set_format_mtree },
48228753Smm	{ ARCHIVE_FORMAT_SHAR,		archive_write_set_format_shar },
49228753Smm	{ ARCHIVE_FORMAT_SHAR_BASE,	archive_write_set_format_shar },
50228753Smm	{ ARCHIVE_FORMAT_SHAR_DUMP,	archive_write_set_format_shar_dump },
51228753Smm	{ ARCHIVE_FORMAT_TAR,	archive_write_set_format_pax_restricted },
52228753Smm	{ ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE, archive_write_set_format_pax },
53228753Smm	{ ARCHIVE_FORMAT_TAR_PAX_RESTRICTED,
54228753Smm				archive_write_set_format_pax_restricted },
55228753Smm	{ ARCHIVE_FORMAT_TAR_USTAR,	archive_write_set_format_ustar },
56228753Smm	{ ARCHIVE_FORMAT_ZIP,	archive_write_set_format_zip },
57228753Smm	{ 0,		NULL }
58228753Smm};
59228753Smm
60228753Smmint
61228753Smmarchive_write_set_format(struct archive *a, int code)
62228753Smm{
63228753Smm	int i;
64228753Smm
65228753Smm	for (i = 0; codes[i].code != 0; i++) {
66228753Smm		if (code == codes[i].code)
67228753Smm			return ((codes[i].setter)(a));
68228753Smm	}
69228753Smm
70228753Smm	archive_set_error(a, EINVAL, "No such format");
71228753Smm	return (ARCHIVE_FATAL);
72228753Smm}
73