Artifact [91ccc08f28]

Artifact 91ccc08f28380616f97a8238daf29f754ccfeee4:


.TH LC_HANDLE_TYPE 3 "25 Oct 04" "@PACKAGE_STRING@"
.SH NAME
lc_handle_type \- Convert string representation of a value to its correct type

.SH SYNOPSIS
.B #include <libconfig.h>
.sp
.BI "int lc_handle_type(lc_var_type_t " type ", const char *" value ", void *" data ");"

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

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

.SH EXAMPLE
.nf
#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);
}
.fi


.SH "SEE ALSO"
.BR libconfig (3),
.BR lc_register_var (3),
.BR lc_register_callback (3),
.BR lc_geterrno (3),
.BR lc_geterrstr (3),
.BR lc_seterrstr (3),
.BR lc_process (3),
.BR lc_process_file (3),
.BR lc_cleanup (3)