archive_write_set_format_by_name.c revision 316338
11539Srgrimes/*- 21539Srgrimes * Copyright (c) 2003-2007 Tim Kientzle 31539Srgrimes * All rights reserved. 41539Srgrimes * 51539Srgrimes * Redistribution and use in source and binary forms, with or without 61539Srgrimes * modification, are permitted provided that the following conditions 71539Srgrimes * are met: 81539Srgrimes * 1. Redistributions of source code must retain the above copyright 91539Srgrimes * notice, this list of conditions and the following disclaimer. 101539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111539Srgrimes * notice, this list of conditions and the following disclaimer in the 121539Srgrimes * documentation and/or other materials provided with the distribution. 131539Srgrimes * 141539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 151539Srgrimes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 161539Srgrimes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 171539Srgrimes * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 181539Srgrimes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 191539Srgrimes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 201539Srgrimes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 211539Srgrimes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 221539Srgrimes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 231539Srgrimes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 241539Srgrimes */ 251539Srgrimes 261539Srgrimes#include "archive_platform.h" 271539Srgrimes__FBSDID("$FreeBSD: stable/10/contrib/libarchive/libarchive/archive_write_set_format_by_name.c 316338 2017-03-31 20:17:30Z mm $"); 281539Srgrimes 291539Srgrimes#ifdef HAVE_SYS_TYPES_H 301539Srgrimes#include <sys/types.h> 311539Srgrimes#endif 321539Srgrimes 3384747Sbde#ifdef HAVE_ERRNO_H 3484699Smike#include <errno.h> 351539Srgrimes#endif 361539Srgrimes#ifdef HAVE_STRING_H 371539Srgrimes#include <string.h> 381539Srgrimes#endif 3993747Smike 4093747Smike#include "archive.h" 41123257Smarcel#include "archive_private.h" 42102227Smike 431539Srgrimes/* A table that maps names to functions. */ 4493747Smikestatic const 4593747Smikestruct { const char *name; int (*setter)(struct archive *); } names[] = 4693747Smike{ 4793747Smike { "7zip", archive_write_set_format_7zip }, 4893747Smike { "ar", archive_write_set_format_ar_bsd }, 4993747Smike { "arbsd", archive_write_set_format_ar_bsd }, 5093747Smike { "argnu", archive_write_set_format_ar_svr4 }, 5193747Smike { "arsvr4", archive_write_set_format_ar_svr4 }, 52102227Smike { "bsdtar", archive_write_set_format_pax_restricted }, 53102227Smike { "cd9660", archive_write_set_format_iso9660 }, 54102227Smike { "cpio", archive_write_set_format_cpio }, 551539Srgrimes { "gnutar", archive_write_set_format_gnutar }, 561539Srgrimes { "iso", archive_write_set_format_iso9660 }, 571539Srgrimes { "iso9660", archive_write_set_format_iso9660 }, 58105128Smike { "mtree", archive_write_set_format_mtree }, 59105128Smike { "mtree-classic", archive_write_set_format_mtree_classic }, 60105128Smike { "newc", archive_write_set_format_cpio_newc }, 61132564Stjr { "odc", archive_write_set_format_cpio }, 62178051Sdelphij { "oldtar", archive_write_set_format_v7tar }, 63132564Stjr { "pax", archive_write_set_format_pax }, 6493747Smike { "paxr", archive_write_set_format_pax_restricted }, 65149469Sandre { "posix", archive_write_set_format_pax }, 66149466Sandre { "raw", archive_write_set_format_raw }, 67149469Sandre { "rpax", archive_write_set_format_pax_restricted }, 6893032Simp { "shar", archive_write_set_format_shar }, 6993032Simp { "shardump", archive_write_set_format_shar_dump }, 70105128Smike { "ustar", archive_write_set_format_ustar }, 71105128Smike { "v7tar", archive_write_set_format_v7tar }, 72132564Stjr { "v7", archive_write_set_format_v7tar }, 73105128Smike { "warc", archive_write_set_format_warc }, 7493747Smike { "xar", archive_write_set_format_xar }, 75132564Stjr { "zip", archive_write_set_format_zip }, 76132564Stjr { NULL, NULL } 7793032Simp}; 7893747Smike 79132564Stjrint 80105128Smikearchive_write_set_format_by_name(struct archive *a, const char *name) 81187961Sdas{ 82105128Smike int i; 8393032Simp 84105128Smike for (i = 0; names[i].name != NULL; i++) { 85105128Smike if (strcmp(name, names[i].name) == 0) 86105128Smike return ((names[i].setter)(a)); 87105128Smike } 88105128Smike 89105128Smike archive_set_error(a, EINVAL, "No such format '%s'", name); 90105128Smike a->state = ARCHIVE_STATE_FATAL; 91132564Stjr return (ARCHIVE_FATAL); 92105128Smike} 93152754Sru