diff options
Diffstat (limited to 'lib/util.c')
-rw-r--r-- | lib/util.c | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/lib/util.c b/lib/util.c deleted file mode 100644 index 895ca89..0000000 --- a/lib/util.c +++ /dev/null @@ -1,62 +0,0 @@ -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include "util.h" - -#define BUF_SIZE 100 - -char* copy_achar(const char* src) -{ - int len = strlen(src) + 1; - char* dest = (char*)malloc(sizeof(char)*len); - strcpy(dest, src); - - return dest; -} - -int load_or_save_db(sqlite3 *pInMemory, const char *zFilename, int isSave) -{ - int rc; /* Function return code */ - sqlite3 *pFile; /* Database connection opened on zFilename */ - sqlite3_backup *pBackup; /* Backup object used to copy data */ - sqlite3 *pTo; /* Database to copy to (pFile or pInMemory) */ - sqlite3 *pFrom; /* Database to copy from (pFile or pInMemory) */ - - rc = sqlite3_open(zFilename, &pFile); - if( rc==SQLITE_OK ) { - pFrom = (isSave ? pInMemory : pFile); - pTo = (isSave ? pFile : pInMemory); - - pBackup = sqlite3_backup_init(pTo, "main", pFrom, "main"); - if( pBackup ) { - (void)sqlite3_backup_step(pBackup, -1); - (void)sqlite3_backup_finish(pBackup); - } - rc = sqlite3_errcode(pTo); - } - - (void)sqlite3_close(pFile); - return rc; -} - -unsigned int count_file_lines(FILE *file) -{ - char buf[BUF_SIZE]; - unsigned int counter = 0; - for(;;) { - size_t res = fread(buf, 1, BUF_SIZE, file); - if (ferror(file)) - return -1; - - size_t i; - for(i = 0; i < res; i++) - if (buf[i] == '\n') - counter++; - - if (feof(file)) - break; - } - - return counter; -} |