1: .TH LC_HANDLE_TYPE 3 "25 Oct 04" "@PACKAGE_STRING@" 2: .SH NAME 3: lc_handle_type \- Convert string representation of a value to its correct type 4: 5: .SH SYNOPSIS 6: .B #include <libconfig.h> 7: .sp 8: .BI "int lc_handle_type(lc_var_type_t " type ", const char *" value ", void *" data ");" 9: 10: .SH DESCRIPTION 11: .BR lc_handle_type (3) 12: converts the string 13: .I value 14: to the correct type specified by the 15: .I type 16: parameter. The result is stored in the memory region passed as 17: .IR data , 18: which should be of the correct type. For possible values for 19: .I type 20: and the corresponding 21: .I data 22: type, see the 23: .BR lc_register_var (3) 24: man page. 25: 26: .SH "RETURN VALUE" 27: On success 0 is returned, otherwise -1 is returned. The memory pointed to by 28: .I data 29: may be altered in either case. 30: 31: .SH EXAMPLE 32: .nf 33: #include <libconfig.h> 34: #include <stdlib.h> 35: #include <stdio.h> 36: 37: int callback_size(const char *shortvar, const char *var, 38: const char *arguments, const char *value, 39: lc_flags_t flags, void *extra) { 40: size_t size; 41: int lc_ht_ret; 42: 43: if (value == NULL) { 44: lc_seterrstr("You must specify an argument to \\ 45: Size."); 46: return(LC_CBRET_ERROR); 47: } 48: 49: lc_ht_ret = lc_handle_type(LC_VAR_SIZE_SIZE_T, value, &size); 50: if (lc_ht_ret != 0) { 51: lc_seterrstr("Invalid size specified."); 52: return(LC_CBRET_ERROR); 53: } 54: 55: printf("Size: %lu\\n", (unsigned long) size); 56: 57: return(LC_CBRET_OKAY); 58: } 59: 60: int main(int argc, char **argv) { 61: int lc_rc_ret, lc_p_ret; 62: 63: lc_rc_ret = lc_register_callback("Size", 0, LC_VAR_SIZE_SIZE_T, 64: callback_size, NULL); 65: 66: if (lc_rc_ret != 0) { 67: fprintf(stderr, "Error registering callback.\\n"); 68: return(EXIT_FAILURE); 69: } 70: 71: lc_p_ret = lc_process(argc, argv, "example", LC_CONF_APACHE, 72: NULL); 73: 74: lc_cleanup(); 75: 76: if (lc_p_ret != 0) { 77: fprintf(stderr, "Error processing configuration: \\ 78: %s\\n", lc_geterrstr()); 79: return(EXIT_FAILURE); 80: } 81: 82: return(EXIT_SUCCESS); 83: } 84: .fi 85: 86: 87: .SH "SEE ALSO" 88: .BR libconfig (3), 89: .BR lc_register_var (3), 90: .BR lc_register_callback (3), 91: .BR lc_geterrno (3), 92: .BR lc_geterrstr (3), 93: .BR lc_seterrstr (3), 94: .BR lc_process (3), 95: .BR lc_process_file (3), 96: .BR lc_cleanup (3) |