map.c revision ef421f66f47224a42073deaf087378c5d0c9952e
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Automated Testing Framework (atf)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * All rights reserved.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Redistribution and use in source and binary forms, with or without
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * modification, are permitted provided that the following conditions
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * 1. Redistributions of source code must retain the above copyright
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * notice, this list of conditions and the following disclaimer.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * 2. Redistributions in binary form must reproduce the above copyright
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * notice, this list of conditions and the following disclaimer in the
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * documentation and/or other materials provided with the distribution.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt/* ---------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Auxiliary functions.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * --------------------------------------------------------------------- */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntnew_entry(const char *key, void *value, bool managed)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt/* ---------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * The "atf_map_citer" type.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * --------------------------------------------------------------------- */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt newciter.m_listiter = atf_list_citer_next(citer.m_listiter);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_equal_map_citer_map_citer(const atf_map_citer_t i1,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return i1.m_map == i2.m_map && i1.m_entry == i2.m_entry;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt/* ---------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * The "atf_map_iter" type.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * --------------------------------------------------------------------- */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt newiter.m_listiter = atf_list_iter_next(iter.m_listiter);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_equal_map_iter_map_iter(const atf_map_iter_t i1,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return i1.m_map == i2.m_map && i1.m_entry == i2.m_entry;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt/* ---------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * The "atf_map" type.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * --------------------------------------------------------------------- */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Constructors and destructors.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_map_init_charpp(atf_map_t *m, const char *const *array)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = atf_libc_error(EINVAL, "List too short; no value for "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "key '%s' provided", key); /* XXX: Not really libc_error */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = atf_map_insert(m, key, strdup(value), true);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt iter.m_entry = atf_list_iter_data(iter.m_listiter);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt citer.m_entry = atf_list_citer_data(citer.m_listiter);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_map_find_c(const atf_map_t *m, const char *key)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const struct map_entry *me = atf_list_citer_data(iter);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt array = malloc(sizeof(char *) * (atf_map_size(l) * 2 + 1));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt array[i + 1] = strdup((const char *)atf_map_citer_data(iter));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Modifiers.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_map_insert(atf_map_t *m, const char *key, void *value, bool managed)