ライブラリを使用してlibconfig、ファイルから構成データを読み取っています。情報を解析して後でクリーンアップする関数を抽出するのに苦労しています。
実行strcpy(*hostname, tmp)すると、コア ダンプが発生します。
hostname、port、およびipは に初期化されNULLます。
int parseConfig(char **hostname, char **port, char **ip) {
config_t cfg, *cf;
const char *tmp;
cf = &cfg;
config_init(cf);
if(!config_read_file(cf, CONFIG)) {
fprintf(stderr, "%s:%d - %s\n",
config_error_file(cf),
config_error_line(cf),
config_error_text(cf));
config_destroy(cf);
return(EXIT_FAILURE);
}
config_lookup_string(cf, "hostname", &tmp);
strcpy(*hostname, tmp);
config_lookup_string(cf, "ip", &tmp);
strcpy(*ip, tmp);
config_lookup_string(cf, "port", &tmp);
strcpy(*port, tmp);
config_destroy(cf);
return(EXIT_SUCCESS);
}