From 5c126dea86277d63e17a40cbdbc710817e9a06ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=B6hler?= Date: Sun, 21 Jan 2007 16:38:42 +0000 Subject: [PATCH] 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 --- lib/libqof/backend/file/qsf-backend.c | 7 ++- lib/libqof/qof/guid.c | 10 +-- lib/libqof/qof/qofid.h | 2 +- lib/libqof/qof/qoflog.c | 7 ++- src/app-utils/file-utils.c | 3 +- src/backend/file/gnc-backend-file.c | 63 ++++++++++--------- src/backend/file/io-example-account.c | 3 +- src/backend/file/io-gncxml-v2.c | 16 ++--- src/backend/file/sixtp.c | 3 +- src/backend/file/test/test-file-stuff.c | 8 +-- src/backend/file/test/test-load-xml2.c | 6 +- src/backend/file/test/test-save-in-lang.c | 7 ++- src/backend/file/test/test-xml-account.c | 4 +- src/backend/file/test/test-xml-commodity.c | 4 +- src/backend/file/test/test-xml-pricedb.c | 4 +- src/backend/file/test/test-xml-transaction.c | 4 +- src/core-utils/gnc-gkeyfile-utils.c | 4 +- src/engine/TransLog.c | 4 +- src/engine/gnc-filepath-utils.c | 20 ++---- src/gnome-utils/druid-gconf-setup.c | 3 +- src/gnome-utils/gnc-html.c | 3 +- src/gnome/druid-hierarchy.c | 3 +- src/import-export/csv/gnc-csv2glist.c | 4 +- src/import-export/hbci/druid-hbci-initial.c | 3 +- src/import-export/hbci/gnc-file-aqb-import.c | 4 +- src/import-export/log-replay/gnc-log-replay.c | 4 +- src/import-export/qif/qif-file.c | 4 +- .../report-gnome/gnc-plugin-page-report.c | 3 +- 28 files changed, 107 insertions(+), 103 deletions(-) diff --git a/lib/libqof/backend/file/qsf-backend.c b/lib/libqof/backend/file/qsf-backend.c index 9deece890f..7de96b7804 100644 --- a/lib/libqof/backend/file/qsf-backend.c +++ b/lib/libqof/backend/file/qsf-backend.c @@ -23,6 +23,7 @@ #include "config.h" #include +#include #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); diff --git a/lib/libqof/qof/guid.c b/lib/libqof/qof/guid.c index 3ee4b8801c..1d924776ef 100644 --- a/lib/libqof/qof/guid.c +++ b/lib/libqof/qof/guid.c @@ -31,8 +31,8 @@ #include #include #include +#include #include -#include #include #include #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; diff --git a/lib/libqof/qof/qofid.h b/lib/libqof/qof/qofid.h index 5b87ab403a..2b58991d57 100644 --- a/lib/libqof/qof/qofid.h +++ b/lib/libqof/qof/qofid.h @@ -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 */ diff --git a/lib/libqof/qof/qoflog.c b/lib/libqof/qof/qoflog.c index b7d96c58e2..5b46c08644 100644 --- a/lib/libqof/qof/qoflog.c +++ b/lib/libqof/qof/qoflog.c @@ -27,6 +27,7 @@ #include "config.h" #include +#include #ifdef HAVE_UNISTD_H #include #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(); } diff --git a/src/app-utils/file-utils.c b/src/app-utils/file-utils.c index ded797ca32..791b8853e2 100644 --- a/src/app-utils/file-utils.c +++ b/src/app-utils/file-utils.c @@ -22,6 +22,7 @@ #include "config.h" #include +#include #include #include #include @@ -90,7 +91,7 @@ gncReadFile (const char * file, char ** data) if (!filename) return 0; /* Open file: */ - fd = open( filename, O_RDONLY ); + fd = g_open( filename, O_RDONLY ); g_free(filename); filename = NULL; diff --git a/src/backend/file/gnc-backend-file.c b/src/backend/file/gnc-backend-file.c index c2188a7b03..c272aa86e7 100644 --- a/src/backend/file/gnc-backend-file.c +++ b/src/backend/file/gnc-backend-file.c @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -91,7 +92,7 @@ gnc_file_be_get_file_lock (FileBackend *be) int rc; QofBackendError be_err; - rc = stat (be->lockfile, &statbuf); + rc = g_stat (be->lockfile, &statbuf); if (!rc) { /* oops .. file is locked by another user .. */ @@ -99,7 +100,7 @@ gnc_file_be_get_file_lock (FileBackend *be) return FALSE; } - be->lockfd = open (be->lockfile, O_RDWR | O_CREAT | O_EXCL , 0); + be->lockfd = g_open (be->lockfile, O_RDWR | O_CREAT | O_EXCL , 0); if (be->lockfd < 0) { /* oops .. we can't create the lockfile .. */ @@ -154,29 +155,29 @@ gnc_file_be_get_file_lock (FileBackend *be) /* Otherwise, something else is wrong. */ qof_backend_set_error ((QofBackend*)be, ERR_BACKEND_LOCKED); - unlink (pathbuf); + g_unlink (pathbuf); close (be->lockfd); - unlink (be->lockfile); + g_unlink (be->lockfile); return FALSE; } - rc = stat (be->lockfile, &statbuf); + rc = g_stat (be->lockfile, &statbuf); if (rc) { /* oops .. stat failed! This can't happen! */ qof_backend_set_error ((QofBackend*)be, ERR_BACKEND_LOCKED); - unlink (pathbuf); + g_unlink (pathbuf); close (be->lockfd); - unlink (be->lockfile); + g_unlink (be->lockfile); return FALSE; } if (statbuf.st_nlink != 2) { qof_backend_set_error ((QofBackend*)be, ERR_BACKEND_LOCKED); - unlink (pathbuf); + g_unlink (pathbuf); close (be->lockfd); - unlink (be->lockfile); + g_unlink (be->lockfile); return FALSE; } @@ -218,7 +219,7 @@ file_session_begin(QofBackend *be_start, QofSession *session, int rc; /* Again check whether the directory can be accessed */ - rc = stat (be->dirname, &statbuf); + rc = g_stat (be->dirname, &statbuf); if (rc != 0 || !S_ISDIR(statbuf.st_mode)) { /* Error on stat or if it isn't a directory means we @@ -229,8 +230,8 @@ file_session_begin(QofBackend *be_start, QofSession *session, return; } - /* Now check whether we can stat(2) the file itself */ - rc = stat (be->fullpath, &statbuf); + /* Now check whether we can g_stat the file itself */ + rc = g_stat (be->fullpath, &statbuf); if ((rc != 0) && (!create_if_nonexistent)) { /* Error on stat means the file doesn't exist */ @@ -277,7 +278,7 @@ file_session_end(QofBackend *be_start) ENTER (" "); if (be->linkfile) - unlink (be->linkfile); + g_unlink (be->linkfile); if (be->lockfd > 0) close (be->lockfd); @@ -286,16 +287,16 @@ file_session_end(QofBackend *be_start) int rv; #ifdef G_OS_WIN32 /* On windows, we need to allow write-access before - unlink() can succeed */ + g_unlink() can succeed */ rv = chmod (be->lockfile, S_IWRITE | S_IREAD); if (rv) { PWARN("Error on chmod(%s): %d: %s", be->lockfile, errno, strerror(errno) ? strerror(errno) : ""); } #endif - rv = unlink (be->lockfile); + rv = g_unlink (be->lockfile); if (rv) { - PWARN("Error on unlink(%s): %d: %s", be->lockfile, + PWARN("Error on g_unlink(%s): %d: %s", be->lockfile, errno, strerror(errno) ? strerror(errno) : ""); } } @@ -341,7 +342,7 @@ copy_file(const char *orig, const char *bkup) ssize_t count_write; ssize_t count_read; - orig_fd = open(orig, O_RDONLY); + orig_fd = g_open(orig, O_RDONLY); if(orig_fd == -1) { return FALSE; @@ -445,10 +446,10 @@ gnc_determine_file_type (const char *path) if (!path) { return FALSE; } if (0 == safe_strcmp(path, QOF_STDOUT)) { return FALSE; } - t = fopen(path, "r"); + t = g_fopen(path, "r"); if(!t) { PINFO (" new file"); return TRUE; } fclose(t); - rc = stat(path, &sbuf); + rc = g_stat(path, &sbuf); if(rc < 0) { return FALSE; } if (sbuf.st_size == 0) { PINFO (" empty file"); return TRUE; } if(gnc_is_xml_data_file_v2(path, NULL)) { return TRUE; } @@ -469,7 +470,7 @@ gnc_file_be_backup_file(FileBackend *be) datafile = be->fullpath; - rc = stat (datafile, &statbuf); + rc = g_stat (datafile, &statbuf); if (rc) return (errno == ENOENT); @@ -542,8 +543,8 @@ gnc_file_be_write_to_file(FileBackend *fbe, if (gnc_book_write_to_xml_file_v2(book, tmp_name, fbe->file_compression)) { - /* Record the file's permissions before unlinking it */ - rc = stat(datafile, &statbuf); + /* Record the file's permissions before g_unlinking it */ + rc = g_stat(datafile, &statbuf); if(rc == 0) { /* Use the permissions from the original data file */ @@ -581,7 +582,7 @@ gnc_file_be_write_to_file(FileBackend *fbe, } #endif } - if(unlink(datafile) != 0 && errno != ENOENT) + if(g_unlink(datafile) != 0 && errno != ENOENT) { qof_backend_set_error(be, ERR_FILEIO_BACKUP_ERROR); PWARN("unable to unlink filename %s: %s", @@ -596,7 +597,7 @@ gnc_file_be_write_to_file(FileBackend *fbe, g_free(tmp_name); return FALSE; } - if(unlink(tmp_name) != 0) + if(g_unlink(tmp_name) != 0) { qof_backend_set_error(be, ERR_BACKEND_PERM); PWARN("unable to unlink temp filename %s: %s", @@ -615,7 +616,7 @@ gnc_file_be_write_to_file(FileBackend *fbe, } else { - if(unlink(tmp_name) != 0) + if(g_unlink(tmp_name) != 0) { switch (errno) { case ENOENT: /* tmp_name doesn't exist? Assume "RO" error */ @@ -658,7 +659,7 @@ gnc_file_be_remove_old_files(FileBackend *be) int pathlen; time_t now; - if (stat (be->lockfile, &lockstatbuf) != 0) + if (g_stat (be->lockfile, &lockstatbuf) != 0) return; pathlen = strlen(be->fullpath); @@ -702,11 +703,11 @@ gnc_file_be_remove_old_files(FileBackend *be) /* Is a lock file. Skip the active lock file */ (safe_strcmp(name, be->linkfile) != 0) && /* Only delete lock files older than the active one */ - (stat(name, &statbuf) == 0) && + (g_stat(name, &statbuf) == 0) && (statbuf.st_mtime file_retention_days > 0) { @@ -731,8 +732,8 @@ gnc_file_be_remove_old_files(FileBackend *be) && file_time > 0 && days > be->file_retention_days) { - PINFO ("unlink stale (%d days old) file: %s", days, name); - unlink(name); + PINFO ("g_unlink stale (%d days old) file: %s", days, name); + g_unlink(name); } } } @@ -930,7 +931,7 @@ gnc_file_be_save_may_clobber_data (QofBackend *bend) /* FIXME: Make sure this doesn't need more sophisticated semantics * in the face of special file, devices, pipes, symlinks, etc. */ - if (stat(bend->fullpath, &statbuf) == 0) return TRUE; + if (g_stat(bend->fullpath, &statbuf) == 0) return TRUE; return FALSE; } diff --git a/src/backend/file/io-example-account.c b/src/backend/file/io-example-account.c index 75eb61e4b5..b838dd9d18 100644 --- a/src/backend/file/io-example-account.c +++ b/src/backend/file/io-example-account.c @@ -32,6 +32,7 @@ #include #include +#include #include "sixtp.h" #include "gnc-engine.h" @@ -372,7 +373,7 @@ gnc_write_example_account(GncExampleAccount *gea, const gchar *filename) { FILE *out; - out = fopen(filename, "w"); + out = g_fopen(filename, "w"); if (out == NULL) { return FALSE; diff --git a/src/backend/file/io-gncxml-v2.c b/src/backend/file/io-gncxml-v2.c index 79df7bc7fd..a007c7f3ba 100644 --- a/src/backend/file/io-gncxml-v2.c +++ b/src/backend/file/io-gncxml-v2.c @@ -22,7 +22,7 @@ #include "config.h" #include -#include +#include #include #include #include @@ -1239,11 +1239,11 @@ try_gz_open (const char *filename, const char *perms, gboolean use_gzip, use_gzip = TRUE; if (!use_gzip) - return fopen(filename, perms); + return g_fopen(filename, perms); #ifdef G_OS_WIN32 PWARN("Compression not implemented on Windows. Opening uncompressed file."); - return fopen(filename, perms); + return g_fopen(filename, perms); /* Potential implementation: Windows doesn't have pipe(); use the g_spawn glib wrappers. */ @@ -1264,7 +1264,7 @@ try_gz_open (const char *filename, const char *perms, gboolean use_gzip, &child_stdin, NULL, NULL, &error) ) { PWARN("G_spawn call failed. Opening uncompressed file."); - return fopen(filename, perms); + return g_fopen(filename, perms); } /* FIXME: Now need to set up the child process to write to the file. */ @@ -1286,14 +1286,14 @@ try_gz_open (const char *filename, const char *perms, gboolean use_gzip, if (pipe(filedes) < 0) { PWARN("Pipe call failed. Opening uncompressed file."); - return fopen(filename, perms); + return g_fopen(filename, perms); } pid = fork(); switch (pid) { case -1: PWARN("Fork call failed. Opening uncompressed file."); - return fopen(filename, perms); + return g_fopen(filename, perms); case 0: /* child */ { char buffer[BUFLEN]; @@ -1405,7 +1405,7 @@ gnc_book_write_accounts_to_xml_file_v2( { FILE *out; - out = fopen(filename, "w"); + out = g_fopen(filename, "w"); if (out == NULL) { return FALSE; @@ -1428,7 +1428,7 @@ static gboolean is_gzipped_file(const gchar *name) { unsigned char buf[2]; - int fd = open(name, O_RDONLY); + int fd = g_open(name, O_RDONLY); if (fd == -1) { return FALSE; diff --git a/src/backend/file/sixtp.c b/src/backend/file/sixtp.c index d22e96bffe..97dc667b47 100644 --- a/src/backend/file/sixtp.c +++ b/src/backend/file/sixtp.c @@ -24,6 +24,7 @@ #include "config.h" #include +#include #include #include #include @@ -843,7 +844,7 @@ gnc_is_our_xml_file(const char *filename, const char *first_tag, g_return_val_if_fail(filename, FALSE); g_return_val_if_fail(first_tag, FALSE); - f = fopen(filename, "r"); + f = g_fopen(filename, "r"); if (f == NULL) { return FALSE; } diff --git a/src/backend/file/test/test-file-stuff.c b/src/backend/file/test/test-file-stuff.c index 28cd9f1a05..6d6f1e33f2 100644 --- a/src/backend/file/test/test-file-stuff.c +++ b/src/backend/file/test/test-file-stuff.c @@ -28,10 +28,10 @@ #include #include #include -#include #include #include #include +#include #include "gnc-engine.h" #include "sixtp-dom-parsers.h" @@ -58,8 +58,8 @@ files_compare(const gchar* f1, const gchar* f2) int fd1, fd2; int amount_read1, amount_read2; - fd1 = open(f1, O_RDONLY); - fd2 = open(f2, O_RDONLY); + fd1 = g_open(f1, O_RDONLY); + fd2 = g_open(f2, O_RDONLY); do { @@ -372,7 +372,7 @@ test_files_in_dir(int argc, char **argv, gxpf_callback cb, { struct stat file_info; const char *to_open = argv[count]; - if(stat(to_open, &file_info) != 0) + if(g_stat(to_open, &file_info) != 0) { printf("cannot stat %s.\n", to_open); failure("unable to stat file"); diff --git a/src/backend/file/test/test-load-xml2.c b/src/backend/file/test/test-load-xml2.c index e4c3ee630a..03f0460d19 100644 --- a/src/backend/file/test/test-load-xml2.c +++ b/src/backend/file/test/test-load-xml2.c @@ -28,7 +28,6 @@ #include "config.h" #include -#include #include #include #include @@ -36,6 +35,7 @@ #include #include #include +#include #include "cashobjects.h" #include "Group.h" @@ -63,9 +63,9 @@ remove_locks(const char *filename) { to_remove = g_strdup_printf("%s.LCK", filename); - if(stat(to_remove, &buf) != -1) + if(g_stat(to_remove, &buf) != -1) { - unlink(to_remove); + g_unlink(to_remove); } g_free(to_remove); } diff --git a/src/backend/file/test/test-save-in-lang.c b/src/backend/file/test/test-save-in-lang.c index aa77ea4d8c..058df28c3f 100644 --- a/src/backend/file/test/test-save-in-lang.c +++ b/src/backend/file/test/test-save-in-lang.c @@ -1,5 +1,6 @@ #include "config.h" #include +#include #include #include #include @@ -153,9 +154,9 @@ main(int argc, char **argv) struct stat file_info; char* filename; - filename = g_strdup_printf("%s/%s", test_dir, next_file); - - if(stat(filename, &file_info) != 0) + filename = g_build_filename(test_dir, next_file, (gchar*) NULL); + + if(g_stat(filename, &file_info) != 0) { failure_args("stat", __FILE__, __LINE__, "couldn't stat file %s: %s", filename, diff --git a/src/backend/file/test/test-xml-account.c b/src/backend/file/test/test-xml-account.c index 7ce1ae0710..43d6b4e9a8 100644 --- a/src/backend/file/test/test-xml-account.c +++ b/src/backend/file/test/test-xml-account.c @@ -25,7 +25,7 @@ #include "config.h" #include -#include +#include #include #include @@ -274,7 +274,7 @@ test_account(int i, Account *test_act) } - unlink(filename1); + g_unlink(filename1); g_free(filename1); xmlFreeNode(test_node); } diff --git a/src/backend/file/test/test-xml-commodity.c b/src/backend/file/test/test-xml-commodity.c index fd0d140dd9..b285a6714a 100644 --- a/src/backend/file/test/test-xml-commodity.c +++ b/src/backend/file/test/test-xml-commodity.c @@ -1,8 +1,8 @@ #include "config.h" #include +#include #include -#include #include #include @@ -204,7 +204,7 @@ test_generation(void) /* sixtp_destroy(parser); */ } - unlink(filename1); + g_unlink(filename1); g_free(filename1); gnc_commodity_destroy(ran_com); xmlFreeNode(test_node); diff --git a/src/backend/file/test/test-xml-pricedb.c b/src/backend/file/test/test-xml-pricedb.c index b294994057..d912ec5aee 100644 --- a/src/backend/file/test/test-xml-pricedb.c +++ b/src/backend/file/test/test-xml-pricedb.c @@ -25,7 +25,7 @@ #include "config.h" #include -#include +#include #include #include @@ -116,7 +116,7 @@ test_db (int i, GNCPriceDB *db) } } - unlink (filename1); + g_unlink (filename1); g_free (filename1); xmlFreeNode (test_node); } diff --git a/src/backend/file/test/test-xml-transaction.c b/src/backend/file/test/test-xml-transaction.c index 6c3a215c73..297d81fd82 100644 --- a/src/backend/file/test/test-xml-transaction.c +++ b/src/backend/file/test/test-xml-transaction.c @@ -25,7 +25,7 @@ #include "config.h" #include -#include +#include #include #include @@ -473,7 +473,7 @@ test_transaction(void) /* sixtp_destroy(parser); */ } - unlink(filename1); + g_unlink(filename1); g_free(filename1); really_get_rid_of_transaction(ran_trn); xmlFreeNode(test_node); diff --git a/src/core-utils/gnc-gkeyfile-utils.c b/src/core-utils/gnc-gkeyfile-utils.c index 68428df55a..defc2987bd 100644 --- a/src/core-utils/gnc-gkeyfile-utils.c +++ b/src/core-utils/gnc-gkeyfile-utils.c @@ -37,7 +37,7 @@ #include "config.h" #include -#include +#include #include #include #include @@ -97,7 +97,7 @@ gnc_key_file_save_to_file (const gchar *filename, contents = g_key_file_to_data(key_file, NULL, NULL); length = strlen(contents); - fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); + fd = g_open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd == -1) { if (error) { *error = g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno), diff --git a/src/engine/TransLog.c b/src/engine/TransLog.c index 7d1bb796b6..4c545aef26 100644 --- a/src/engine/TransLog.c +++ b/src/engine/TransLog.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include "Account.h" @@ -157,7 +157,7 @@ xaccOpenLog (void) filename = g_strconcat (log_base_name, ".", timestamp, ".log", NULL); - trans_log = fopen (filename, "a"); + trans_log = g_fopen (filename, "a"); if (!trans_log) { int norr = errno; printf ("Error: xaccOpenLog(): cannot open journal \n" diff --git a/src/engine/gnc-filepath-utils.c b/src/engine/gnc-filepath-utils.c index ffb495c649..8ce4459595 100644 --- a/src/engine/gnc-filepath-utils.c +++ b/src/engine/gnc-filepath-utils.c @@ -59,8 +59,6 @@ static QofLogModule log_module = GNC_MOD_BACKEND; static void MakeHomeDir (void) { - int rc; - struct stat statbuf; const gchar *home; char *path; char *data; @@ -71,19 +69,15 @@ MakeHomeDir (void) path = g_build_filename(home, ".gnucash", (gchar *)NULL); - rc = stat (path, &statbuf); - if (rc) + if (!g_file_test(path, G_FILE_TEST_EXISTS)) { - /* assume that the stat failed only because the dir is absent, - * and not because its read-protected or other error. - * Go ahead and make it. Don't bother much with checking mkdir + /* Go ahead and make it. Don't bother much with checking mkdir * for errors; seems pointless. */ g_mkdir (path, S_IRWXU); /* perms = S_IRWXU = 0700 */ } data = g_build_filename (path, "data", (gchar *)NULL); - rc = stat (data, &statbuf); - if (rc) + if (!g_file_test(data, G_FILE_TEST_EXISTS)) g_mkdir (data, S_IRWXU); g_free (path); @@ -182,7 +176,6 @@ xaccUserPathPathGenerator(char *pathbuf, int which) char * xaccResolveFilePath (const char * filefrag) { - struct stat statbuf; char pathbuf[PATH_MAX]; pathGenerator gens[4]; char *filefrag_dup; @@ -226,8 +219,7 @@ xaccResolveFilePath (const char * filefrag) { gchar *fullpath = g_build_filename(pathbuf, filefrag, (gchar *)NULL); - int rc = stat (fullpath, &statbuf); - if ((!rc) && (S_ISREG(statbuf.st_mode))) + if (g_file_test(fullpath, G_FILE_TEST_IS_REGULAR)) { return fullpath; } @@ -314,7 +306,7 @@ gnc_validate_directory (const gchar *dirname) struct stat statbuf; gint rc; - rc = stat (dirname, &statbuf); + rc = g_stat (dirname, &statbuf); if (rc) { switch (errno) { case ENOENT: @@ -328,7 +320,7 @@ gnc_validate_directory (const gchar *dirname) dirname, strerror(errno), errno); exit(1); } - stat (dirname, &statbuf); + g_stat (dirname, &statbuf); break; case EACCES: diff --git a/src/gnome-utils/druid-gconf-setup.c b/src/gnome-utils/druid-gconf-setup.c index 5b58057156..a317fd8536 100644 --- a/src/gnome-utils/druid-gconf-setup.c +++ b/src/gnome-utils/druid-gconf-setup.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -138,7 +139,7 @@ druid_gconf_update_path (GError **error) g_strfreev(lines); } - output = fopen(path_filename, "a"); + output = g_fopen(path_filename, "a"); if (output == NULL) { *error = g_error_new (G_FILE_ERROR, g_file_error_from_errno(errno), diff --git a/src/gnome-utils/gnc-html.c b/src/gnome-utils/gnc-html.c index 4e8daf2306..82e5959c20 100644 --- a/src/gnome-utils/gnc-html.c +++ b/src/gnome-utils/gnc-html.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -1312,7 +1313,7 @@ gnc_html_export(gnc_html * html, const char *filepath) g_return_val_if_fail (html != NULL, FALSE); g_return_val_if_fail (filepath != NULL, FALSE); - fh = fopen (filepath, "w"); + fh = g_fopen (filepath, "w"); if (!fh) return FALSE; diff --git a/src/gnome/druid-hierarchy.c b/src/gnome/druid-hierarchy.c index e3c911c776..a7688830fd 100644 --- a/src/gnome/druid-hierarchy.c +++ b/src/gnome/druid-hierarchy.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -202,7 +203,7 @@ gnc_get_ea_locale_dir(const char *top_dir) i = strlen(locale); ret = g_build_filename(top_dir, locale, (char *)NULL); - while (stat(ret, &buf) != 0) + while (g_stat(ret, &buf) != 0) { i--; if (i<1) diff --git a/src/import-export/csv/gnc-csv2glist.c b/src/import-export/csv/gnc-csv2glist.c index 2f4f3fdc9a..b00921e414 100644 --- a/src/import-export/csv/gnc-csv2glist.c +++ b/src/import-export/csv/gnc-csv2glist.c @@ -23,7 +23,7 @@ //#include "config.h" #include -#include +#include #include #include #include @@ -175,7 +175,7 @@ int main (int argc, char **argv) { printf("usage:\n\tcsv2glist fname.csv\n"); } - fp = fopen (argv[1], "r"); + fp = g_fopen (argv[1], "r"); if (fp == NULL) return 1; parsed_csv = gnc_csv_parse(fp); diff --git a/src/import-export/hbci/druid-hbci-initial.c b/src/import-export/hbci/druid-hbci-initial.c index 80b669bee2..7cb34d611d 100644 --- a/src/import-export/hbci/druid-hbci-initial.c +++ b/src/import-export/hbci/druid-hbci-initial.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #ifdef HAVE_SYS_WAIT_H @@ -532,7 +533,7 @@ on_aqhbci_button (GtkButton *button, if (wizard_exists) { /* Really check whether the file exists */ - int fd = open( wizard_path, O_RDONLY ); + int fd = g_open( wizard_path, O_RDONLY ); if ( fd == -1) wizard_exists = FALSE; else diff --git a/src/import-export/hbci/gnc-file-aqb-import.c b/src/import-export/hbci/gnc-file-aqb-import.c index d91c336887..1051420fec 100644 --- a/src/import-export/hbci/gnc-file-aqb-import.c +++ b/src/import-export/hbci/gnc-file-aqb-import.c @@ -27,7 +27,7 @@ #include #include -#include +#include #include #include #include @@ -169,7 +169,7 @@ void gnc_file_aqbanking_import (const gchar *aqbanking_importername, DEBUG("Filename found: %s",selected_filename); DEBUG("Opening selected file"); - dtaus_fd = open(selected_filename, O_RDONLY); + dtaus_fd = g_open(selected_filename, O_RDONLY); if (dtaus_fd == -1) { DEBUG("Could not open file %s", selected_filename); return; diff --git a/src/import-export/log-replay/gnc-log-replay.c b/src/import-export/log-replay/gnc-log-replay.c index 9bfc6f4b2b..a2e17d1381 100644 --- a/src/import-export/log-replay/gnc-log-replay.c +++ b/src/import-export/log-replay/gnc-log-replay.c @@ -27,7 +27,7 @@ #include #include -#include +#include #include #include #include @@ -542,7 +542,7 @@ void gnc_file_log_replay (void) selected_filename); } else { DEBUG("Opening selected file"); - log_file = fopen(selected_filename, "r"); + log_file = g_fopen(selected_filename, "r"); if(!log_file || ferror(log_file)!=0) { int err = errno; perror("File open failed"); diff --git a/src/import-export/qif/qif-file.c b/src/import-export/qif/qif-file.c index 382b84a6e9..bc1605fc59 100644 --- a/src/import-export/qif/qif-file.c +++ b/src/import-export/qif/qif-file.c @@ -28,7 +28,7 @@ #endif #include -#include +#include #include #include "gnc-engine.h" @@ -206,7 +206,7 @@ qif_import_file(QifContext ctx, const char *filename) g_return_val_if_fail(*filename, QIF_E_BADARGS); /* Open the file */ - fp = fopen(filename, "r"); + fp = g_fopen(filename, "r"); if (fp == NULL) return QIF_E_NOFILE; diff --git a/src/report/report-gnome/gnc-plugin-page-report.c b/src/report/report-gnome/gnc-plugin-page-report.c index 2018fb1e86..9be89358e5 100644 --- a/src/report/report-gnome/gnc-plugin-page-report.c +++ b/src/report/report-gnome/gnc-plugin-page-report.c @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -1312,7 +1313,7 @@ gnc_get_export_filename (SCM choice) if (!filepath) return NULL; - rc = stat (filepath, &statbuf); + rc = g_stat (filepath, &statbuf); /* Check for an error that isn't a non-existant file. */ if (rc != 0 && errno != ENOENT)