lib/libc/citrus/citrus_mapper.c
static int
lookup_mapper_entry(const char *dir, const char *mapname,
		    void *linebuf, size_t linebufsize,
		    const char **module, const char **variable)
{
	struct _region r;
	struct _memstream ms;
	int ret;
	const char *cp, *cq;
	char *p;
	size_t len;
	char path[PATH_MAX];

	/* create mapper.dir path */
	snprintf(path, PATH_MAX, "%s/%s", dir, _CITRUS_MAPPER_DIR);

	/* open read stream */
	ret = _map_file(&r, path);
	if (ret)
		return ret;

	_memstream_bind(&ms, &r);

	/* search the line matching to the map name */
	cp = _memstream_matchline(&ms, mapname, &len, 0);
	if (!cp) {
		ret = ENOENT;
		goto quit;
	}
	if (!len || len>linebufsize-1) {
		ret = EINVAL;
		goto quit;
	}

	p = linebuf;
	/* get module name */
	*module = p;
	cq = _bcs_skip_nonws_len(cp, &len);
	strlcpy(p, cp, (size_t)(cq-cp+1));
	p += cq-cp+1;

	/* get variable */
	*variable = p;
	cp = _bcs_skip_ws_len(cq, &len);
	strlcpy(p, cp, len+1);

	ret = 0;

quit:
	_unmap_file(&r);
	return ret;
}
/*
 * lookup_mapper_entry:
 *	lookup mapper.dir entry in the specified directory.
 *
 * line format of iconv.dir file:
 *	mapper	module	arg
 * mapper : mapper name.
 * module : mapper module name.
 * arg    : argument for the module (generally, description file name)
 */
lookup mapper.dir entry in the specified directory.

line format of iconv.dir file:
mapper  module  arg
mapper : mapper name.
module : mapper module name.
arg    : argument for the module (generally, description file name)
lookup mapper . dir entry in the specified directory . line format of iconv . dir file : mapper module arg mapper : mapper name . module : mapper module name . arg : argument for the module ( generally description file name )
static int
lookup_mapper_entry(const char *dir, const char *mapname,
		    void *linebuf, size_t linebufsize,
		    const char **module, const char **variable)
{
	struct _region r;
	struct _memstream ms;
	int ret;
	const char *cp, *cq;
	char *p;
	size_t len;
	char path[PATH_MAX];
	snprintf(path, PATH_MAX, "%s/%s", dir, _CITRUS_MAPPER_DIR);
	ret = _map_file(&r, path);
	if (ret)
		return ret;
	_memstream_bind(&ms, &r);
	cp = _memstream_matchline(&ms, mapname, &len, 0);
	if (!cp) {
		ret = ENOENT;
		goto quit;
	}
	if (!len || len>linebufsize-1) {
		ret = EINVAL;
		goto quit;
	}
	p = linebuf;
	*module = p;
	cq = _bcs_skip_nonws_len(cp, &len);
	strlcpy(p, cp, (size_t)(cq-cp+1));
	p += cq-cp+1;
	*variable = p;
	cp = _bcs_skip_ws_len(cq, &len);
	strlcpy(p, cp, len+1);
	ret = 0;
quit:
	_unmap_file(&r);
	return ret;
}
static int lookup_mapper_entry ( const char * dir , const char * mapname , void * linebuf , size_t linebufsize , const char * * module , const char * * variable ) { struct _region r ; struct _memstream ms ; int ret ; const char * cp , * cq ; char * p ; size_t len ; char path [ PATH_MAX ] ; snprintf ( path , PATH_MAX , " " , dir , _CITRUS_MAPPER_DIR ) ; ret = _map_file ( & r , path ) ; if ( ret ) return ret ; _memstream_bind ( & ms , & r ) ; cp = _memstream_matchline ( & ms , mapname , & len , 0 ) ; if ( ! cp ) { ret = ENOENT ; goto quit ; } if ( ! len || len > linebufsize - 1 ) { ret = EINVAL ; goto quit ; } p = linebuf ; * module = p ; cq = _bcs_skip_nonws_len ( cp , & len ) ; strlcpy ( p , cp , ( size_t ) ( cq - cp + 1 ) ) ; p += cq - cp + 1 ; * variable = p ; cp = _bcs_skip_ws_len ( cq , & len ) ; strlcpy ( p , cp , len + 1 ) ; ret = 0 ; quit : _unmap_file ( & r ) ; return ret ; }
lookup_mapper_entry:
      lookup mapper.dir entry in the specified directory.
lookup_mapper_entry : lookup mapper . dir entry in the specified directory .
/* create mapper.dir path */ /* open read stream */ /* search the line matching to the map name */ /* get module name */ /* get variable */