.
D 2014-11-24T20:11:51.115
L Manual\sfor\slc_handle_type
P 9731b0f7e7b1b36299f3a2de67eba2d561be16a3
U rkeene
W 3423
<H2>NAME</H2>
lc_handle_type - Convert string representation of a value to its correct type
<P>
<A NAME="lbAC"> </A>
<H2>SYNOPSIS</H2>
<B>#include <<A HREF="artifact/7c61a9805e664fde7943807af8d5e164e7cebdb6">libconfig.h</A>></B>
<P>
<B>int lc_handle_type(lc_var_type_t </B><I>type</I><B>, const char *</B><I>value</I><B>, void *</B><I>data</I><B>);</B>
<P>
<A NAME="lbAD"> </A>
<H2>DESCRIPTION</H2>
<B><A HREF="wiki/Manual for lc_handle_type">lc_handle_type</A></B>(3)
converts the string
<I>value</I>
to the correct type specified by the
<I>type </I>
parameter. The result is stored in the memory region passed as
<I>data</I>,
which should be of the correct type. For possible values for
<I>type</I>
and the corresponding
<I>data</I>
type, see the
<B><A HREF="wiki/Manual for lc_register_var">lc_register_var</A></B>(3)
man page.
<P>
<A NAME="lbAE"> </A>
<H2>RETURN VALUE</H2>
On success 0 is returned, otherwise -1 is returned. The memory pointed to by
<I>data</I>
may be altered in either case.
<P>
<A NAME="lbAF"> </A>
<H2>EXAMPLE</H2>
<PRE>
#include <<A HREF="artifact/7c61a9805e664fde7943807af8d5e164e7cebdb6">libconfig.h</A>>
#include <<A HREF="file:/usr/include/stdlib.h">stdlib.h</A>>
#include <<A HREF="file:/usr/include/stdio.h">stdio.h</A>>
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);
}
</PRE>
<P>
<P>
<A NAME="lbAG"> </A>
<H2>SEE ALSO</H2>
<B><A HREF="wiki/Manual">libconfig</A></B>(3),
<B><A HREF="wiki/Manual for lc_register_var">lc_register_var</A></B>(3),
<B><A HREF="wiki/Manual for lc_register_callback">lc_register_callback</A></B>(3),
<B><A HREF="wiki/Manual for lc_geterrno">lc_geterrno</A></B>(3),
<B><A HREF="wiki/Manual for lc_geterrstr">lc_geterrstr</A></B>(3),
<B><A HREF="wiki/Manual for lc_seterrstr">lc_seterrstr</A></B>(3),
<B><A HREF="wiki/Manual for lc_process">lc_process</A></B>(3),
<B><A HREF="wiki/Manual for lc_process_file">lc_process_file</A></B>(3),
<B><A HREF="wiki/Manual for lc_cleanup">lc_cleanup</A></B>(3)
<P>
Z 20b322f0bf6dabedc5f8ddac41be5bd6