From 4e8844f1bbccab218a4d02572b892d126eaf7e85 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 20 Mar 2008 10:45:05 +0100 Subject: [PATCH] Use POSIX functions for journal check. --- src/csync_journal.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/csync_journal.c b/src/csync_journal.c index 6da2c7f19e..54a743b720 100644 --- a/src/csync_journal.c +++ b/src/csync_journal.c @@ -24,6 +24,9 @@ #include #include #include +#include +#include +#include #include "c_lib.h" #include "csync_private.h" @@ -33,16 +36,16 @@ #include "csync_log.h" static int csync_journal_check(const char *journal) { - FILE *fp = NULL; + int fd = -1; char buf[16] = {0}; sqlite3 *db = NULL; /* check db version */ - fp = fopen(journal, "r"); - if (fp) { - if (fread((void *) buf, (size_t) 16, 1, fp) == 0) { + fd = open(journal, O_RDONLY); + if (fd >= 0) { + if (read(fd, (void *) buf, (size_t) 16) >= 0) { buf[16] = '\0'; - fclose(fp); + close(fd); if (c_streq(buf, "SQLite format 3")) { if (sqlite3_open(journal, &db ) == SQLITE_OK) { /* everything is fine */