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" 27228763Smm__FBSDID("$FreeBSD: stable/10/contrib/libarchive/libarchive/archive_write_set_format_by_name.c 316338 2017-03-31 20:17:30Z mm $"); 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#ifdef HAVE_STRING_H 37228753Smm#include <string.h> 38228753Smm#endif 39228753Smm 40228753Smm#include "archive.h" 41228753Smm#include "archive_private.h" 42228753Smm 43228753Smm/* A table that maps names to functions. */ 44316338Smmstatic const 45228753Smmstruct { const char *name; int (*setter)(struct archive *); } names[] = 46228753Smm{ 47232153Smm { "7zip", archive_write_set_format_7zip }, 48228753Smm { "ar", archive_write_set_format_ar_bsd }, 49228753Smm { "arbsd", archive_write_set_format_ar_bsd }, 50228753Smm { "argnu", archive_write_set_format_ar_svr4 }, 51228753Smm { "arsvr4", archive_write_set_format_ar_svr4 }, 52232153Smm { "bsdtar", archive_write_set_format_pax_restricted }, 53232153Smm { "cd9660", archive_write_set_format_iso9660 }, 54228753Smm { "cpio", archive_write_set_format_cpio }, 55232153Smm { "gnutar", archive_write_set_format_gnutar }, 56232153Smm { "iso", archive_write_set_format_iso9660 }, 57232153Smm { "iso9660", archive_write_set_format_iso9660 }, 58228753Smm { "mtree", archive_write_set_format_mtree }, 59248616Smm { "mtree-classic", archive_write_set_format_mtree_classic }, 60228753Smm { "newc", archive_write_set_format_cpio_newc }, 61228753Smm { "odc", archive_write_set_format_cpio }, 62248616Smm { "oldtar", archive_write_set_format_v7tar }, 63228753Smm { "pax", archive_write_set_format_pax }, 64232153Smm { "paxr", archive_write_set_format_pax_restricted }, 65228753Smm { "posix", archive_write_set_format_pax }, 66302001Smm { "raw", archive_write_set_format_raw }, 67232153Smm { "rpax", archive_write_set_format_pax_restricted }, 68228753Smm { "shar", archive_write_set_format_shar }, 69228753Smm { "shardump", archive_write_set_format_shar_dump }, 70228753Smm { "ustar", archive_write_set_format_ustar }, 71248616Smm { "v7tar", archive_write_set_format_v7tar }, 72248616Smm { "v7", archive_write_set_format_v7tar }, 73302001Smm { "warc", archive_write_set_format_warc }, 74232153Smm { "xar", archive_write_set_format_xar }, 75228753Smm { "zip", archive_write_set_format_zip }, 76228753Smm { NULL, NULL } 77228753Smm}; 78228753Smm 79228753Smmint 80228753Smmarchive_write_set_format_by_name(struct archive *a, const char *name) 81228753Smm{ 82228753Smm int i; 83228753Smm 84228753Smm for (i = 0; names[i].name != NULL; i++) { 85228753Smm if (strcmp(name, names[i].name) == 0) 86228753Smm return ((names[i].setter)(a)); 87228753Smm } 88228753Smm 89228753Smm archive_set_error(a, EINVAL, "No such format '%s'", name); 90232153Smm a->state = ARCHIVE_STATE_FATAL; 91228753Smm return (ARCHIVE_FATAL); 92228753Smm} 93