-1
我有必須通過調用調用的庫程序在GNU/Linux的無限循環
extern int read(char** argv, int argc); // from header
讀取SQLite數據庫數據的庫運行它必須處理:
int read(char** argv, int argc) {
char* lineborder1;
char* lineborder2;
char* spaces1;
char* spaces2;
int maxl2 = 0, maxl1 = 0;
int i, maxi1, maxi2;
if (prelude() == -1) return -1;
// etc...
其中前奏是sqlite連接的內部過程:
int prelude() {
timefile = 0;
f = NULL;
#ifndef WIN32
char* temp = (char*)calloc(200, sizeof(char));
#endif
queries = (char**)malloc(sizeof(char*) * q_cnt);
for (x = 0; x < q_cnt; x++) {
queries[x] = (char*)malloc(sizeof(char) * q_size);
}
#ifdef WIN32
retval = sqlite3_open("todo.db3", &handle);
#else
home = (char*)getenv("HOME");
strcpy(temp, home);
retval = sqlite3_open(strcat(temp, "/.todo.db3"), &handle);
free(temp);
#endif
if (retval) {
printf("Database connection failed\n\r");
return -1;
}
return 0;
}
整個來源在這裏:bitbucket: ctodo.c
我從我的應用程序中調用這個讀:
else if ((strcmp(argv[1], "read") == 0) || (strcmp(argv[1], "r") == 0)) {
return read(argv, argc);
,但得到這個read
通話的無限循環:
>>./todo r
Database connection failed
Database connection failed
Database connection failed
.... etc
這裏是如何構建它:
gcc -I . -c -o todo.a ctodo.c -lsqlite3 -O3
gcc -I . -o todo cctodo.c -lsqlite3 -O3 todo.a
help
或version
調用wrok罰款和閱讀工作正常w indows,特定於我的Linux版本的東西在這裏,但到目前爲止我找不到一個bug。什麼可以稱此read
像這樣在無限循環中運行?
+ 1爲最後的聲明;-) – 2012-11-20 07:43:11
哦,太棒了)我必須記住使用前綴命名庫api:P https://bitbucket.org/Cynede/ ctodo/changeset/6168a9f19ff055baa18001ea7c646836(但windows compier可以正常工作:D) – Cynede