我无法使用 C 和 libconfig 从我的配置文件中检索用户值。
配置阅读器.h
#include <stdio.h>
#include <string.h>
#include <libconfig.h>
#ifndef CONFIGREADER_H_INCLUDED
#define CONFIGREADER_H_INCLUDED
char *userreader(){
static const char *inputfile = "/opt/plaininc/config/handler.conf";
config_t configreader;
const char *userconfig;
if(! config_read_file(&configreader, inputfile)){
config_destroy(&configreader);
exit(EXIT_FAILURE);
}
if (config_lookup_string(&configreader, "handler.user", &userconfig)){
config_destroy(&configreader);
return userconfig;
} else {
config_destroy(&configreader);
exit(EXIT_FAILURE);
}
}
#endif
配置文件
#include <stdio.h>
#include <stdlib.h>
#include "configreader.h"
int main(){
const char *user = userreader();
printf("%s", user);
}
广发银行:
程序收到信号 SIGSEGV,分段错误。/lib/i386-linux-gnu/libc.so.6 中的 free() 中的 0xb7e63496