/*-
* Copyright (c)2003 Citrus Project,
* All rights reserved.
*
* 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 AUTHOR 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 AUTHOR 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.
*/
if (cl->cl_rewind)
_memstream_bind(&cl->cl_plainms, &cl->cl_plainr);
cl->cl_rewind = 0;
retry:
p = _memstream_getln(&cl->cl_plainms, &len);
if (p == NULL)
return ENOENT;
/* ignore comment */
q = memchr(p, T_COMM, len);
if (q) {
len = q-p;
}
/* ignore trailing spaces */
_bcs_trunc_rws_len(p, &len);
p = _bcs_skip_ws_len(p, &len);
q = _bcs_skip_nonws_len(p, &len);
if (p==q)
goto retry;
if (cl->cl_key && ((size_t)(q-p) != cl->cl_keylen ||
memcmp(p, cl->cl_key, (size_t)(q-p)) != 0))
goto retry;
/* found a entry */
if (key)
_region_init(key, __UNCONST(p), (size_t)(q-p));
p = _bcs_skip_ws_len(q, &len);
if (data)
_region_init(data, len ? __UNCONST(p) : NULL, len);
return 0;
}
static int
seq_get_num_entries_plain(struct _citrus_lookup *cl)
{
int num;
num = 0;
while (seq_next_plain(cl, NULL, NULL) == 0)
num++;