gnokii:API错误?

我有以下代码的问题:
#include <stdio.h>
#include <stdlib.h>

#include <string.h>
#include <gnokii.h>

#define CONFIG_FILE "config"

struct gn_statemachine  *state;

void terminate(void) {
    gn_lib_phone_close(state);
    gn_lib_phoneprofile_free(&state);
    gn_lib_library_free();
}


int main() {
    gn_data data;
    gn_error error;    
    gn_sms_folder_list folderlist;

    atexit(terminate);

    if((error = gn_lib_phoneprofile_load(CONFIG_FILE,&state)) 
       != GN_ERR_NONE)
    {
        fprintf(stderr,"%sn",gn_error_print(error));
        exit(1);
    }

    memset(&folderlist,0,sizeof(gn_sms_folder_list));
    gn_data_clear(&data);
    data.sms_folder_list = &folderlist;

    error = gn_sm_functions(GN_OP_GetSMSFolders, &data, state);

    printf("ada %d sms dunn",folderlist.number);

    return 0;
}
我用
gcc -o main main.c -lgnokii
编译它,但是当它被执行时,它在查找配置文件时会产生错误:
# ./gnokiitest 
No phone_config section in the config file.
Either global or given phone section cannot be found.
Segmentation fault
因为我将配置文件包含在主输出的一个文件夹中:
$ cat config 
[global]
  connection = bluetooth
  port = 24:22:AB:AB:C1:F8
  model = AT
  rfcomm_channel = 2
什么错了呢?     
已邀请:
对于初学者,以下将导致问题:
if((error = gn_lib_phoneprofile_load(CONFIG_FILE,&state))
state
变量未在此处初始化。这将导致随机指针被传递,并且很可能是段错误。 接下来,
gn_lib_phoneprofile_load()
的第一个参数不是配置文件名,而是配置中提供连接详细信息的电话部分。鉴于您将
config
作为此参数传递,您需要:
[phone_config]
connection = bluetooth
port = 24:22:AB:AB:C1:F8
model = AT
rfcomm_channel = 2
但放在标准的gnokii配置文件位置。要使用不同的位置使用:
gn_lib_phoneprofile_load_from_file(CONFIG_FILE, NULL, &state);
第二个参数是电话部分名称。如果为NULL,则使用
[global]
。 另外
gn_lib_phoneprofile_load()
只读取配置文件。您需要运行
gn_lib_phone_open()
来初始化连接。 最后,已经编写了类似的代码,无需重新发明轮子:http://git.savannah.gnu.org/cgit/gnokii/gnokii-extras.git/tree/snippets/sms/sms_status.c     

要回复问题请先登录注册