static int
parse_file(struct _citrus_mapper_646 *m6, const char *path)
{
	struct _memstream ms;
	struct _region r;
	const char *p;
	char *pp;
	size_t len;
	char buf[PATH_MAX];
	int i, ret;

	ret = _map_file(&r, path);
	if (ret)
		return (ret);
	_memstream_bind(&ms, &r);
	for (i = 0; i < NUM_OF_SPECIALS; i++) {
retry:
		p = _memstream_getln(&ms, &len);
		if (p == NULL) {
			ret = EINVAL;
			break;
		}
		p = _bcs_skip_ws_len(p, &len);
		if (*p == T_COMM || len==0)
			goto retry;
		if (!_bcs_isdigit(*p)) {
			ret = EINVAL;
			break;
		}
		snprintf(buf, sizeof(buf), "%.*s", (int)len, p);
		pp = __DECONST(void *, p);
		m6->m6_map[i] = strtoul(buf, (char **)&pp, 0);
		p = _bcs_skip_ws(buf);
		if (*p != T_COMM && !*p) {
			ret = EINVAL;
			break;
		}
	}
	_unmap_file(&r);

	return (ret);
};
Exemple #2
0
static int
seq_next_plain(struct _citrus_lookup *cl, struct _region *key,
	       struct _region *data)
{
	const char *p, *q;
	size_t len;

	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;
}