/*-
* Copyright (c) 2006, 2025 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* ARGSUSED */
static _prop_object_free_rv_t
_prop_bool_free(prop_stack_t stack, prop_object_t *obj)
{
/*
* This should never happen as we "leak" our initial reference
* count.
*/
if (! (prop_object_is_bool(b1) &&
prop_object_is_bool(b2)))
return (_PROP_OBJECT_EQUALS_FALSE);
/*
* Since we only ever allocate one true and one false,
* save ourselves a couple of memory operations.
*/
if (b1 == b2)
return (_PROP_OBJECT_EQUALS_TRUE);
else
return (_PROP_OBJECT_EQUALS_FALSE);
}
_PROP_ONCE_RUN(_prop_bool_init_once, _prop_bool_init);
pb = val ? &_prop_bool_true : &_prop_bool_false;
prop_object_retain(pb);
return (pb);
}
/*
* prop_bool_create --
* Create a prop_bool_t and initialize it with the
* provided boolean value.
*/
_PROP_EXPORT prop_bool_t
prop_bool_create(bool val)
{
/*
* Because we only ever allocate one true and one false, this
* can be reduced to a simple retain operation.
*/
prop_object_retain(opb);
return (opb);
}
/*
* prop_bool_value --
* Get the value of a prop_bool_t.
*/
_PROP_EXPORT bool
prop_bool_value(prop_bool_t pb)
{
if (! prop_object_is_bool(pb))
return (false);
return (pb->pb_value);
}
/*
* prop_bool_true --
* Historical alias for prop_bool_value().
*/
_PROP_EXPORT bool
prop_bool_true(prop_bool_t pb)
{
return prop_bool_value(pb);
}
/*
* prop_bool_equals --
* Return true if the boolean values are equivalent.
*/
_PROP_EXPORT bool
prop_bool_equals(prop_bool_t b1, prop_bool_t b2)
{
if (!prop_object_is_bool(b1) || !prop_object_is_bool(b2))
return (false);
return (prop_object_equals(b1, b2));
}
/*
* _prop_bool_internalize --
* Parse a <true/> or <false/> and return the object created from
* the external representation.
*/