LC_HANDLE_TYPE(3)

NAME
lc_handle_type - Convert string representation of a value to its correct type

SYNOPSIS
#include <libconfig.h>

int lc_handle_type(lc_var_type_t type, const char *value, void *data);

DESCRIPTION
lc_handle_type(3) converts the string value to the correct type specified by the type parameter. The result is stored in the memory region passed as data, which should be of the correct type. For possible values for type and the corresponding data type, see the lc_register_var(3) man page.

RETURN VALUE
On success 0 is returned, otherwise -1 is returned. The memory pointed to by data may be altered in either case.

EXAMPLE
#include <libconfig.h>
#include <stdlib.h>
#include <stdio.h>
int callback_size(const char *shortvar, const char *var,
                  const char *arguments, const char *value,
                  lc_flags_t flags, void *extra) {
	size_t size;
	int lc_ht_ret;
	if (value == NULL) {
		lc_seterrstr("You must specify an argument to \
		              Size.");
		return(LC_CBRET_ERROR);
	}
	lc_ht_ret = lc_handle_type(LC_VAR_SIZE_SIZE_T, value, &size);
	if (lc_ht_ret != 0) {
		lc_seterrstr("Invalid size specified.");
		return(LC_CBRET_ERROR);
	}
	printf("Size: %lu\n", (unsigned long) size);
	return(LC_CBRET_OKAY);
}
int main(int argc, char **argv) {
	int lc_rc_ret, lc_p_ret;
	lc_rc_ret = lc_register_callback("Size", 0, LC_VAR_SIZE_SIZE_T,
	                                 callback_size, NULL);
	if (lc_rc_ret != 0) {
		fprintf(stderr, "Error registering callback.\n");
		return(EXIT_FAILURE);
	}
	lc_p_ret = lc_process(argc, argv, "example", LC_CONF_APACHE,
	                      NULL);
	lc_cleanup();
	if (lc_p_ret != 0) {
		fprintf(stderr, "Error processing configuration: \
		        %s\n", lc_geterrstr());
		return(EXIT_FAILURE);
	}
	return(EXIT_SUCCESS);
}

SEE ALSO
libconfig(3), lc_register_var(3), lc_register_callback(3), lc_geterrno(3), lc_geterrstr(3), lc_seterrstr(3), lc_process(3), lc_process_file(3), lc_cleanup(3)