示例#1
0
文件: util_list.c 项目: Machyne/mongo
/*
 * list_get_allocsize --
 *	Get the allocation size for this file from the metadata.
 */
static int
list_get_allocsize(WT_SESSION *session, const char *key, size_t *allocsize)
{
	WT_CONFIG_ITEM szvalue;
	WT_CONFIG_PARSER *parser;
	WT_DECL_RET;
	WT_EXTENSION_API *wt_api;
	int tret;
	char *config;

	wt_api = session->connection->get_extension_api(session->connection);
	if ((ret = wt_api->metadata_search(wt_api, session, key, &config)) != 0)
		return (util_err(
		    session, ret, "%s: WT_EXTENSION_API.metadata_search", key));
	if ((ret = wt_api->config_parser_open(wt_api, session, config,
	    strlen(config), &parser)) != 0)
		return (util_err(
		    session, ret, "WT_EXTENSION_API.config_parser_open"));
	if ((ret = parser->get(parser, "allocation_size", &szvalue)) != 0) {
		if (ret == WT_NOTFOUND) {
			*allocsize = 0;
			ret = 0;
		} else
			ret = util_err(session, ret, "WT_CONFIG_PARSER.get");
		if ((tret = parser->close(parser)) != 0)
			(void)util_err(session, tret, "WT_CONFIG_PARSER.close");
		return (ret);
	}
	if ((ret = parser->close(parser)) != 0)
		return (util_err(session, ret, "WT_CONFIG_PARSER.close"));
	*allocsize = (size_t)szvalue.val;
	return (0);
}
示例#2
0
/*
 * csv_customize --
 *	The customize function creates a customized extractor,
 *	needed to save the field number and format.
 */
static int
csv_customize(WT_EXTRACTOR *extractor, WT_SESSION *session,
    const char *uri, WT_CONFIG_ITEM *appcfg, WT_EXTRACTOR **customp)
{
	const CSV_EXTRACTOR *orig;
	CSV_EXTRACTOR *csv_extractor;
	WT_CONFIG_ITEM field, format;
	WT_CONFIG_PARSER *parser;
	WT_EXTENSION_API *wtapi;
	int ret;
	long field_num;

	(void)session;				/* Unused parameters */
	(void)uri;				/* Unused parameters */

	orig = (const CSV_EXTRACTOR *)extractor;
	wtapi = orig->wt_api;
	if ((ret = wtapi->config_parser_open(wtapi, session, appcfg->str,
	    appcfg->len, &parser)) != 0)
		return (ret);
	if ((ret = parser->get(parser, "field", &field)) != 0 ||
	    (ret = parser->get(parser, "format", &format)) != 0) {
		if (ret == WT_NOTFOUND)
			return (EINVAL);
		return (ret);
	}
	field_num = strtol(field.str, NULL, 10);
	if (field_num < 0 || field_num > INT_MAX)
		return (EINVAL);
	if (format.len != 1 || (format.str[0] != 'S' && format.str[0] != 'i'))
		return (EINVAL);
	if ((csv_extractor = calloc(1, sizeof(CSV_EXTRACTOR))) == NULL)
		return (errno);

	*csv_extractor = *orig;
	csv_extractor->field = field_num;
	csv_extractor->format_isnum = (format.str[0] == 'i');
	*customp = (WT_EXTRACTOR *)csv_extractor;
	return (0);
}
示例#3
0
/*
 * csv_customize --
 *	The customize function creates a customized extractor,
 *	needed to save the field number and format.
 */
static int
csv_customize(WT_EXTRACTOR *extractor, WT_SESSION *session,
    const char *uri, WT_CONFIG_ITEM *appcfg, WT_EXTRACTOR **customp)
{
	const CSV_EXTRACTOR *orig;
	CSV_EXTRACTOR *csv_extractor;
	WT_CONFIG_ITEM field, format;
	WT_CONFIG_PARSER *parser;
	WT_EXTENSION_API *wt_api;
	long field_num;
	int ret;

	(void)uri;				/* Unused parameters */

	orig = (const CSV_EXTRACTOR *)extractor;
	wt_api = orig->wt_api;
	if ((ret = wt_api->config_parser_open(wt_api, session, appcfg->str,
	    appcfg->len, &parser)) != 0)
		return (ret);
	if ((ret = parser->get(parser, "field", &field)) != 0) {
		if (ret == WT_NOTFOUND)
			(void)wt_api->err_printf(
			    wt_api, session, "field not found");
		else
			(void)wt_api->err_printf(
			    wt_api, session, "WT_CONFIG_PARSER.get: field: %s",
			    wt_api->strerror(wt_api, session, ret));
		goto err;
	}
	if ((ret = parser->get(parser, "format", &format)) != 0) {
		if (ret == WT_NOTFOUND)
			(void)wt_api->err_printf(
			    wt_api, session, "format not found");
		else
			(void)wt_api->err_printf(
			    wt_api, session, "WT_CONFIG_PARSER.get: format: %s",
			    wt_api->strerror(wt_api, session, ret));
		goto err;
	}
	ret = parser->close(parser);
	parser = NULL;
	if (ret != 0) {
		(void)wt_api->err_printf(
		    wt_api, session, "WT_CONFIG_PARSER.close: %s",
		    wt_api->strerror(wt_api, session, ret));
	}

	field_num = strtol(field.str, NULL, 10);
	if (field_num < 0 || field_num > INT_MAX) {
		(void)wt_api->err_printf(
		    wt_api, session, "field: invalid format");
		ret = EINVAL;
		goto err;
	}
	if (format.len != 1 || (format.str[0] != 'S' && format.str[0] != 'i')) {
		(void)wt_api->err_printf(
		    wt_api, session, "format: invalid format");
		ret = EINVAL;
		goto err;
	}
	if ((csv_extractor = calloc(1, sizeof(CSV_EXTRACTOR))) == NULL) {
		ret = errno;
		goto err;
	}

	*csv_extractor = *orig;
	csv_extractor->field = (int)field_num;
	csv_extractor->format_isnum = (format.str[0] == 'i');
	*customp = (WT_EXTRACTOR *)csv_extractor;
	return (0);

err:	if (parser != NULL)
		(void)parser->close(parser);
	return (ret);
}