Created
December 7, 2014 09:02
-
-
Save jaypeche/ae9e71019b0e251b5830 to your computer and use it in GitHub Desktop.
libconfig readconf.c v1 build with -lconfig flag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <libconfig.h> | |
| int main(int argc, char **argv) | |
| { | |
| config_t cfg, *cf; | |
| const config_setting_t *retries; | |
| const char *base = NULL; | |
| int count, n, enabled; | |
| cf = &cfg; | |
| config_init(cf); | |
| if (!config_read_file(cf, "ldap.cfg")) { | |
| fprintf(stderr, "%s:%d - %s\n", | |
| config_error_file(cf), | |
| config_error_line(cf), | |
| config_error_text(cf)); | |
| config_destroy(cf); | |
| return(EXIT_FAILURE); | |
| } | |
| if (config_lookup_bool(cf, "enabled", &enabled)) | |
| printf("Enabled: %s\n", enabled ? "Yep" : "Nope"); | |
| else | |
| printf("Enabled is not defined\n"); | |
| if (config_lookup_string(cf, "ldap.base", &base)) | |
| printf("Host: %s\n", base); | |
| retries = config_lookup(cf, "ldap.retries"); | |
| count = config_setting_length(retries); | |
| printf("I have %d retries:\n", count); | |
| for (n = 0; n < count; n++) { | |
| printf("\t#%d. %d\n", n + 1, | |
| config_setting_get_int_elem(retries, n)); | |
| } | |
| config_destroy(cf); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment