Use g_open, g_fopen, g_stat and g_unlink.

Replace open, fopen, stat and unlink by their GLib wrappers so that
files on Windows will be handled with the wide character api.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@15407 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Andreas Köhler
2007-01-21 16:38:42 +00:00
parent e79f41ca14
commit 5c126dea86
28 changed files with 107 additions and 103 deletions

View File

@@ -23,6 +23,7 @@
#include "config.h"
#include <glib.h>
#include <glib/gstdio.h>
#include "qof.h"
#include "qofbackend-p.h"
#include "qof-backend-qsf.h"
@@ -205,7 +206,7 @@ qsf_determine_file_type(const gchar *path)
if (!path) { return TRUE; }
if (0 == safe_strcmp(path, QOF_STDOUT)) { return TRUE; }
if (stat(path, &sbuf) <0) { return FALSE; }
if (g_stat(path, &sbuf) <0) { return FALSE; }
if (sbuf.st_size == 0) { return TRUE; }
if(is_our_qsf_object(path)) { return TRUE; }
else if(is_qsf_object(path)) { return TRUE; }
@@ -251,7 +252,7 @@ qsf_session_begin(QofBackend *be, QofSession *session, const gchar *book_path,
{
FILE *f;
f = fopen(qsf_be->fullpath, "a+");
f = g_fopen(qsf_be->fullpath, "a+");
if(f) {fclose(f); }
else
{
@@ -472,7 +473,7 @@ qsf_file_type(QofBackend *be, QofBook *book)
params = qsf_be->params;
params->book = book;
path = g_strdup(qsf_be->fullpath);
f = fopen(path, "r");
f = g_fopen(path, "r");
if(!f) { qof_backend_set_error(be, ERR_FILEIO_READ_ERROR); }
fclose(f);
params->filepath = g_strdup(path);

View File

@@ -31,8 +31,8 @@
#include <ctype.h>
#include <dirent.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#ifdef HAVE_SYS_TIMES_H
@@ -206,7 +206,7 @@ init_from_file(const char *filename, size_t max_size)
FILE *fp;
memset(&stats, 0, sizeof(stats));
if (stat(filename, &stats) != 0)
if (g_stat(filename, &stats) != 0)
return 0;
md5_process_bytes(&stats, sizeof(stats), &guid_context);
@@ -215,7 +215,7 @@ init_from_file(const char *filename, size_t max_size)
if (max_size <= 0)
return total;
fp = fopen (filename, "r");
fp = g_fopen (filename, "r");
if (fp == NULL)
return total;
@@ -265,7 +265,7 @@ init_from_dir(const char *dirname, unsigned int max_files)
continue;
memset(&stats, 0, sizeof(stats));
if (stat(filename, &stats) != 0)
if (g_stat(filename, &stats) != 0)
continue;
md5_process_bytes(&stats, sizeof(stats), &guid_context);
total += sizeof(stats);
@@ -519,7 +519,7 @@ guid_new(GUID *guid)
{
FILE *fp;
fp = fopen ("/dev/urandom", "r");
fp = g_fopen ("/dev/urandom", "r");
if (fp == NULL)
return;

View File

@@ -106,7 +106,7 @@ typedef const gchar* QofLogModule;
if ((da) && (!(db))) { \
val = 1; \
} \
val; /* block assumes value of last statment */ \
val; /* block assumes value of last statement */ \
})
/** return TRUE if object is of the given type */

View File

@@ -27,6 +27,7 @@
#include "config.h"
#include <glib.h>
#include <glib/gstdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#else
@@ -90,13 +91,13 @@ qof_log_init (void)
{
if(!fout) /* allow qof_log_set_file */
{
fout = fopen ("/tmp/qof.trace", "w");
fout = g_fopen ("/tmp/qof.trace", "w");
}
if(!fout && (filename = (gchar *)g_malloc(MAX_TRACE_FILENAME))) {
snprintf(filename, MAX_TRACE_FILENAME-1, "/tmp/qof.trace.%d",
getpid());
fout = fopen (filename, "w");
fout = g_fopen (filename, "w");
g_free(filename);
}
@@ -153,7 +154,7 @@ qof_log_init_filename (const gchar* logfilename)
else
{
filename = g_strdup(logfilename);
fout = fopen(filename, "w");
fout = g_fopen(filename, "w");
}
qof_log_init();
}