lib/libc/citrus/citrus_mapper.c
static int
mapper_open(struct _citrus_mapper_area *__restrict ma,
	    struct _citrus_mapper * __restrict * __restrict rcm,
	    const char * __restrict module,
	    const char * __restrict variable)
{
	int ret;
	struct _citrus_mapper *cm;
	_citrus_mapper_getops_t getops;

	/* initialize mapper handle */
	cm = malloc(sizeof(*cm));
	if (!cm)
		return errno;

	cm->cm_module = NULL;
	cm->cm_ops = NULL;
	cm->cm_closure = NULL;
	cm->cm_traits = NULL;
	cm->cm_refcount = 0;
	cm->cm_key = NULL;

	/* load module */
	ret = _citrus_load_module(&cm->cm_module, module);
	if (ret)
		goto err;

	/* get operators */
	getops = (_citrus_mapper_getops_t)
	    _citrus_find_getops(cm->cm_module, module, "mapper");
	if (!getops) {
		ret = EOPNOTSUPP;
		goto err;
	}
	cm->cm_ops = malloc(sizeof(*cm->cm_ops));
	if (!cm->cm_ops) {
		ret = errno;
		goto err;
	}
	ret = (*getops)(cm->cm_ops, sizeof(*cm->cm_ops),
			_CITRUS_MAPPER_ABI_VERSION);
	if (ret)
		goto err;

	if (!cm->cm_ops->mo_init ||
	    !cm->cm_ops->mo_uninit ||
	    !cm->cm_ops->mo_convert ||
	    !cm->cm_ops->mo_init_state)
		goto err;

	/* allocate traits structure */
	cm->cm_traits = malloc(sizeof(*cm->cm_traits));
	if (cm->cm_traits == NULL) {
		ret = errno;
		goto err;
	}
	/* initialize the mapper */
	ret = (*cm->cm_ops->mo_init)(ma, cm, ma->ma_dir,
				     (const void *)variable,
				     strlen(variable)+1,
				     cm->cm_traits, sizeof(*cm->cm_traits));
	if (ret)
		goto err;

	*rcm = cm;

	return 0;

err:
	mapper_close(cm);
	return ret;
}
/*
 * mapper_open:
 *	simply open a mapper. (without handling hash)
 */
simply open a mapper. (without handling hash)
simply open a mapper . ( without handling hash )
static int
mapper_open(struct _citrus_mapper_area *__restrict ma,
	    struct _citrus_mapper * __restrict * __restrict rcm,
	    const char * __restrict module,
	    const char * __restrict variable)
{
	int ret;
	struct _citrus_mapper *cm;
	_citrus_mapper_getops_t getops;
	cm = malloc(sizeof(*cm));
	if (!cm)
		return errno;
	cm->cm_module = NULL;
	cm->cm_ops = NULL;
	cm->cm_closure = NULL;
	cm->cm_traits = NULL;
	cm->cm_refcount = 0;
	cm->cm_key = NULL;
	ret = _citrus_load_module(&cm->cm_module, module);
	if (ret)
		goto err;
	getops = (_citrus_mapper_getops_t)
	    _citrus_find_getops(cm->cm_module, module, "mapper");
	if (!getops) {
		ret = EOPNOTSUPP;
		goto err;
	}
	cm->cm_ops = malloc(sizeof(*cm->cm_ops));
	if (!cm->cm_ops) {
		ret = errno;
		goto err;
	}
	ret = (*getops)(cm->cm_ops, sizeof(*cm->cm_ops),
			_CITRUS_MAPPER_ABI_VERSION);
	if (ret)
		goto err;
	if (!cm->cm_ops->mo_init ||
	    !cm->cm_ops->mo_uninit ||
	    !cm->cm_ops->mo_convert ||
	    !cm->cm_ops->mo_init_state)
		goto err;
	cm->cm_traits = malloc(sizeof(*cm->cm_traits));
	if (cm->cm_traits == NULL) {
		ret = errno;
		goto err;
	}
	ret = (*cm->cm_ops->mo_init)(ma, cm, ma->ma_dir,
				     (const void *)variable,
				     strlen(variable)+1,
				     cm->cm_traits, sizeof(*cm->cm_traits));
	if (ret)
		goto err;
	*rcm = cm;
	return 0;
err:
	mapper_close(cm);
	return ret;
}
static int mapper_open ( struct _citrus_mapper_area * __restrict ma , struct _citrus_mapper * __restrict * __restrict rcm , const char * __restrict module , const char * __restrict variable ) { int ret ; struct _citrus_mapper * cm ; _citrus_mapper_getops_t getops ; cm = malloc ( sizeof ( * cm ) ) ; if ( ! cm ) return errno ; cm -> cm_module = NULL ; cm -> cm_ops = NULL ; cm -> cm_closure = NULL ; cm -> cm_traits = NULL ; cm -> cm_refcount = 0 ; cm -> cm_key = NULL ; ret = _citrus_load_module ( & cm -> cm_module , module ) ; if ( ret ) goto err ; getops = ( _citrus_mapper_getops_t ) _citrus_find_getops ( cm -> cm_module , module , " " ) ; if ( ! getops ) { ret = EOPNOTSUPP ; goto err ; } cm -> cm_ops = malloc ( sizeof ( * cm -> cm_ops ) ) ; if ( ! cm -> cm_ops ) { ret = errno ; goto err ; } ret = ( * getops ) ( cm -> cm_ops , sizeof ( * cm -> cm_ops ) , _CITRUS_MAPPER_ABI_VERSION ) ; if ( ret ) goto err ; if ( ! cm -> cm_ops -> mo_init || ! cm -> cm_ops -> mo_uninit || ! cm -> cm_ops -> mo_convert || ! cm -> cm_ops -> mo_init_state ) goto err ; cm -> cm_traits = malloc ( sizeof ( * cm -> cm_traits ) ) ; if ( cm -> cm_traits == NULL ) { ret = errno ; goto err ; } ret = ( * cm -> cm_ops -> mo_init ) ( ma , cm , ma -> ma_dir , ( const void * ) variable , strlen ( variable ) + 1 , cm -> cm_traits , sizeof ( * cm -> cm_traits ) ) ; if ( ret ) goto err ; * rcm = cm ; return 0 ; err : mapper_close ( cm ) ; return ret ; }
mapper_open:
      simply open a mapper.
mapper_open : simply open a mapper .
/* initialize mapper handle */ /* load module */ /* get operators */ /* allocate traits structure */ /* initialize the mapper */