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
+4 -3
View File
@@ -23,6 +23,7 @@
#include "config.h" #include "config.h"
#include <glib.h> #include <glib.h>
#include <glib/gstdio.h>
#include "qof.h" #include "qof.h"
#include "qofbackend-p.h" #include "qofbackend-p.h"
#include "qof-backend-qsf.h" #include "qof-backend-qsf.h"
@@ -205,7 +206,7 @@ qsf_determine_file_type(const gchar *path)
if (!path) { return TRUE; } if (!path) { return TRUE; }
if (0 == safe_strcmp(path, QOF_STDOUT)) { 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 (sbuf.st_size == 0) { return TRUE; }
if(is_our_qsf_object(path)) { return TRUE; } if(is_our_qsf_object(path)) { return TRUE; }
else if(is_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; FILE *f;
f = fopen(qsf_be->fullpath, "a+"); f = g_fopen(qsf_be->fullpath, "a+");
if(f) {fclose(f); } if(f) {fclose(f); }
else else
{ {
@@ -472,7 +473,7 @@ qsf_file_type(QofBackend *be, QofBook *book)
params = qsf_be->params; params = qsf_be->params;
params->book = book; params->book = book;
path = g_strdup(qsf_be->fullpath); 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); } if(!f) { qof_backend_set_error(be, ERR_FILEIO_READ_ERROR); }
fclose(f); fclose(f);
params->filepath = g_strdup(path); params->filepath = g_strdup(path);
+5 -5
View File
@@ -31,8 +31,8 @@
#include <ctype.h> #include <ctype.h>
#include <dirent.h> #include <dirent.h>
#include <glib.h> #include <glib.h>
#include <glib/gstdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#ifdef HAVE_SYS_TIMES_H #ifdef HAVE_SYS_TIMES_H
@@ -206,7 +206,7 @@ init_from_file(const char *filename, size_t max_size)
FILE *fp; FILE *fp;
memset(&stats, 0, sizeof(stats)); memset(&stats, 0, sizeof(stats));
if (stat(filename, &stats) != 0) if (g_stat(filename, &stats) != 0)
return 0; return 0;
md5_process_bytes(&stats, sizeof(stats), &guid_context); 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) if (max_size <= 0)
return total; return total;
fp = fopen (filename, "r"); fp = g_fopen (filename, "r");
if (fp == NULL) if (fp == NULL)
return total; return total;
@@ -265,7 +265,7 @@ init_from_dir(const char *dirname, unsigned int max_files)
continue; continue;
memset(&stats, 0, sizeof(stats)); memset(&stats, 0, sizeof(stats));
if (stat(filename, &stats) != 0) if (g_stat(filename, &stats) != 0)
continue; continue;
md5_process_bytes(&stats, sizeof(stats), &guid_context); md5_process_bytes(&stats, sizeof(stats), &guid_context);
total += sizeof(stats); total += sizeof(stats);
@@ -519,7 +519,7 @@ guid_new(GUID *guid)
{ {
FILE *fp; FILE *fp;
fp = fopen ("/dev/urandom", "r"); fp = g_fopen ("/dev/urandom", "r");
if (fp == NULL) if (fp == NULL)
return; return;
+1 -1
View File
@@ -106,7 +106,7 @@ typedef const gchar* QofLogModule;
if ((da) && (!(db))) { \ if ((da) && (!(db))) { \
val = 1; \ 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 */ /** return TRUE if object is of the given type */
+4 -3
View File
@@ -27,6 +27,7 @@
#include "config.h" #include "config.h"
#include <glib.h> #include <glib.h>
#include <glib/gstdio.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#else #else
@@ -90,13 +91,13 @@ qof_log_init (void)
{ {
if(!fout) /* allow qof_log_set_file */ 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))) { if(!fout && (filename = (gchar *)g_malloc(MAX_TRACE_FILENAME))) {
snprintf(filename, MAX_TRACE_FILENAME-1, "/tmp/qof.trace.%d", snprintf(filename, MAX_TRACE_FILENAME-1, "/tmp/qof.trace.%d",
getpid()); getpid());
fout = fopen (filename, "w"); fout = g_fopen (filename, "w");
g_free(filename); g_free(filename);
} }
@@ -153,7 +154,7 @@ qof_log_init_filename (const gchar* logfilename)
else else
{ {
filename = g_strdup(logfilename); filename = g_strdup(logfilename);
fout = fopen(filename, "w"); fout = g_fopen(filename, "w");
} }
qof_log_init(); qof_log_init();
} }
+2 -1
View File
@@ -22,6 +22,7 @@
#include "config.h" #include "config.h"
#include <glib.h> #include <glib.h>
#include <glib/gstdio.h>
#include <libguile.h> #include <libguile.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
@@ -90,7 +91,7 @@ gncReadFile (const char * file, char ** data)
if (!filename) return 0; if (!filename) return 0;
/* Open file: */ /* Open file: */
fd = open( filename, O_RDONLY ); fd = g_open( filename, O_RDONLY );
g_free(filename); filename = NULL; g_free(filename); filename = NULL;
+32 -31
View File
@@ -32,6 +32,7 @@
#include <glib.h> #include <glib.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <libintl.h> #include <libintl.h>
#include <locale.h> #include <locale.h>
#include <stdio.h> #include <stdio.h>
@@ -91,7 +92,7 @@ gnc_file_be_get_file_lock (FileBackend *be)
int rc; int rc;
QofBackendError be_err; QofBackendError be_err;
rc = stat (be->lockfile, &statbuf); rc = g_stat (be->lockfile, &statbuf);
if (!rc) if (!rc)
{ {
/* oops .. file is locked by another user .. */ /* oops .. file is locked by another user .. */
@@ -99,7 +100,7 @@ gnc_file_be_get_file_lock (FileBackend *be)
return FALSE; 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) if (be->lockfd < 0)
{ {
/* oops .. we can't create the lockfile .. */ /* oops .. we can't create the lockfile .. */
@@ -154,29 +155,29 @@ gnc_file_be_get_file_lock (FileBackend *be)
/* Otherwise, something else is wrong. */ /* Otherwise, something else is wrong. */
qof_backend_set_error ((QofBackend*)be, ERR_BACKEND_LOCKED); qof_backend_set_error ((QofBackend*)be, ERR_BACKEND_LOCKED);
unlink (pathbuf); g_unlink (pathbuf);
close (be->lockfd); close (be->lockfd);
unlink (be->lockfile); g_unlink (be->lockfile);
return FALSE; return FALSE;
} }
rc = stat (be->lockfile, &statbuf); rc = g_stat (be->lockfile, &statbuf);
if (rc) if (rc)
{ {
/* oops .. stat failed! This can't happen! */ /* oops .. stat failed! This can't happen! */
qof_backend_set_error ((QofBackend*)be, ERR_BACKEND_LOCKED); qof_backend_set_error ((QofBackend*)be, ERR_BACKEND_LOCKED);
unlink (pathbuf); g_unlink (pathbuf);
close (be->lockfd); close (be->lockfd);
unlink (be->lockfile); g_unlink (be->lockfile);
return FALSE; return FALSE;
} }
if (statbuf.st_nlink != 2) if (statbuf.st_nlink != 2)
{ {
qof_backend_set_error ((QofBackend*)be, ERR_BACKEND_LOCKED); qof_backend_set_error ((QofBackend*)be, ERR_BACKEND_LOCKED);
unlink (pathbuf); g_unlink (pathbuf);
close (be->lockfd); close (be->lockfd);
unlink (be->lockfile); g_unlink (be->lockfile);
return FALSE; return FALSE;
} }
@@ -218,7 +219,7 @@ file_session_begin(QofBackend *be_start, QofSession *session,
int rc; int rc;
/* Again check whether the directory can be accessed */ /* 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)) if (rc != 0 || !S_ISDIR(statbuf.st_mode))
{ {
/* Error on stat or if it isn't a directory means we /* 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; return;
} }
/* Now check whether we can stat(2) the file itself */ /* Now check whether we can g_stat the file itself */
rc = stat (be->fullpath, &statbuf); rc = g_stat (be->fullpath, &statbuf);
if ((rc != 0) && (!create_if_nonexistent)) if ((rc != 0) && (!create_if_nonexistent))
{ {
/* Error on stat means the file doesn't exist */ /* Error on stat means the file doesn't exist */
@@ -277,7 +278,7 @@ file_session_end(QofBackend *be_start)
ENTER (" "); ENTER (" ");
if (be->linkfile) if (be->linkfile)
unlink (be->linkfile); g_unlink (be->linkfile);
if (be->lockfd > 0) if (be->lockfd > 0)
close (be->lockfd); close (be->lockfd);
@@ -286,16 +287,16 @@ file_session_end(QofBackend *be_start)
int rv; int rv;
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
/* On windows, we need to allow write-access before /* On windows, we need to allow write-access before
unlink() can succeed */ g_unlink() can succeed */
rv = chmod (be->lockfile, S_IWRITE | S_IREAD); rv = chmod (be->lockfile, S_IWRITE | S_IREAD);
if (rv) { if (rv) {
PWARN("Error on chmod(%s): %d: %s", be->lockfile, PWARN("Error on chmod(%s): %d: %s", be->lockfile,
errno, strerror(errno) ? strerror(errno) : ""); errno, strerror(errno) ? strerror(errno) : "");
} }
#endif #endif
rv = unlink (be->lockfile); rv = g_unlink (be->lockfile);
if (rv) { 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) : ""); errno, strerror(errno) ? strerror(errno) : "");
} }
} }
@@ -341,7 +342,7 @@ copy_file(const char *orig, const char *bkup)
ssize_t count_write; ssize_t count_write;
ssize_t count_read; ssize_t count_read;
orig_fd = open(orig, O_RDONLY); orig_fd = g_open(orig, O_RDONLY);
if(orig_fd == -1) if(orig_fd == -1)
{ {
return FALSE; return FALSE;
@@ -445,10 +446,10 @@ gnc_determine_file_type (const char *path)
if (!path) { return FALSE; } if (!path) { return FALSE; }
if (0 == safe_strcmp(path, QOF_STDOUT)) { 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; } if(!t) { PINFO (" new file"); return TRUE; }
fclose(t); fclose(t);
rc = stat(path, &sbuf); rc = g_stat(path, &sbuf);
if(rc < 0) { return FALSE; } if(rc < 0) { return FALSE; }
if (sbuf.st_size == 0) { PINFO (" empty file"); return TRUE; } if (sbuf.st_size == 0) { PINFO (" empty file"); return TRUE; }
if(gnc_is_xml_data_file_v2(path, NULL)) { 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; datafile = be->fullpath;
rc = stat (datafile, &statbuf); rc = g_stat (datafile, &statbuf);
if (rc) if (rc)
return (errno == ENOENT); 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)) if (gnc_book_write_to_xml_file_v2(book, tmp_name, fbe->file_compression))
{ {
/* Record the file's permissions before unlinking it */ /* Record the file's permissions before g_unlinking it */
rc = stat(datafile, &statbuf); rc = g_stat(datafile, &statbuf);
if(rc == 0) if(rc == 0)
{ {
/* Use the permissions from the original data file */ /* Use the permissions from the original data file */
@@ -581,7 +582,7 @@ gnc_file_be_write_to_file(FileBackend *fbe,
} }
#endif #endif
} }
if(unlink(datafile) != 0 && errno != ENOENT) if(g_unlink(datafile) != 0 && errno != ENOENT)
{ {
qof_backend_set_error(be, ERR_FILEIO_BACKUP_ERROR); qof_backend_set_error(be, ERR_FILEIO_BACKUP_ERROR);
PWARN("unable to unlink filename %s: %s", PWARN("unable to unlink filename %s: %s",
@@ -596,7 +597,7 @@ gnc_file_be_write_to_file(FileBackend *fbe,
g_free(tmp_name); g_free(tmp_name);
return FALSE; return FALSE;
} }
if(unlink(tmp_name) != 0) if(g_unlink(tmp_name) != 0)
{ {
qof_backend_set_error(be, ERR_BACKEND_PERM); qof_backend_set_error(be, ERR_BACKEND_PERM);
PWARN("unable to unlink temp filename %s: %s", PWARN("unable to unlink temp filename %s: %s",
@@ -615,7 +616,7 @@ gnc_file_be_write_to_file(FileBackend *fbe,
} }
else else
{ {
if(unlink(tmp_name) != 0) if(g_unlink(tmp_name) != 0)
{ {
switch (errno) { switch (errno) {
case ENOENT: /* tmp_name doesn't exist? Assume "RO" error */ case ENOENT: /* tmp_name doesn't exist? Assume "RO" error */
@@ -658,7 +659,7 @@ gnc_file_be_remove_old_files(FileBackend *be)
int pathlen; int pathlen;
time_t now; time_t now;
if (stat (be->lockfile, &lockstatbuf) != 0) if (g_stat (be->lockfile, &lockstatbuf) != 0)
return; return;
pathlen = strlen(be->fullpath); 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 */ /* Is a lock file. Skip the active lock file */
(safe_strcmp(name, be->linkfile) != 0) && (safe_strcmp(name, be->linkfile) != 0) &&
/* Only delete lock files older than the active one */ /* Only delete lock files older than the active one */
(stat(name, &statbuf) == 0) && (g_stat(name, &statbuf) == 0) &&
(statbuf.st_mtime <lockstatbuf.st_mtime)) (statbuf.st_mtime <lockstatbuf.st_mtime))
{ {
PINFO ("unlink lock file: %s", name); PINFO ("unlink lock file: %s", name);
unlink(name); g_unlink(name);
} }
else if (be->file_retention_days > 0) else if (be->file_retention_days > 0)
{ {
@@ -731,8 +732,8 @@ gnc_file_be_remove_old_files(FileBackend *be)
&& file_time > 0 && file_time > 0
&& days > be->file_retention_days) && days > be->file_retention_days)
{ {
PINFO ("unlink stale (%d days old) file: %s", days, name); PINFO ("g_unlink stale (%d days old) file: %s", days, name);
unlink(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 /* FIXME: Make sure this doesn't need more sophisticated semantics
* in the face of special file, devices, pipes, symlinks, etc. */ * 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; return FALSE;
} }
+2 -1
View File
@@ -32,6 +32,7 @@
#include <unistd.h> #include <unistd.h>
#include <glib.h> #include <glib.h>
#include <glib/gstdio.h>
#include "sixtp.h" #include "sixtp.h"
#include "gnc-engine.h" #include "gnc-engine.h"
@@ -372,7 +373,7 @@ gnc_write_example_account(GncExampleAccount *gea, const gchar *filename)
{ {
FILE *out; FILE *out;
out = fopen(filename, "w"); out = g_fopen(filename, "w");
if (out == NULL) if (out == NULL)
{ {
return FALSE; return FALSE;
+8 -8
View File
@@ -22,7 +22,7 @@
#include "config.h" #include "config.h"
#include <glib.h> #include <glib.h>
#include <stdio.h> #include <glib/gstdio.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@@ -1239,11 +1239,11 @@ try_gz_open (const char *filename, const char *perms, gboolean use_gzip,
use_gzip = TRUE; use_gzip = TRUE;
if (!use_gzip) if (!use_gzip)
return fopen(filename, perms); return g_fopen(filename, perms);
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
PWARN("Compression not implemented on Windows. Opening uncompressed file."); 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 /* Potential implementation: Windows doesn't have pipe(); use
the g_spawn glib wrappers. */ 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, &child_stdin, NULL, NULL,
&error) ) { &error) ) {
PWARN("G_spawn call failed. Opening uncompressed file."); 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 /* FIXME: Now need to set up the child process to write to the
file. */ file. */
@@ -1286,14 +1286,14 @@ try_gz_open (const char *filename, const char *perms, gboolean use_gzip,
if (pipe(filedes) < 0) { if (pipe(filedes) < 0) {
PWARN("Pipe call failed. Opening uncompressed file."); PWARN("Pipe call failed. Opening uncompressed file.");
return fopen(filename, perms); return g_fopen(filename, perms);
} }
pid = fork(); pid = fork();
switch (pid) { switch (pid) {
case -1: case -1:
PWARN("Fork call failed. Opening uncompressed file."); PWARN("Fork call failed. Opening uncompressed file.");
return fopen(filename, perms); return g_fopen(filename, perms);
case 0: /* child */ { case 0: /* child */ {
char buffer[BUFLEN]; char buffer[BUFLEN];
@@ -1405,7 +1405,7 @@ gnc_book_write_accounts_to_xml_file_v2(
{ {
FILE *out; FILE *out;
out = fopen(filename, "w"); out = g_fopen(filename, "w");
if (out == NULL) if (out == NULL)
{ {
return FALSE; return FALSE;
@@ -1428,7 +1428,7 @@ static gboolean
is_gzipped_file(const gchar *name) is_gzipped_file(const gchar *name)
{ {
unsigned char buf[2]; unsigned char buf[2];
int fd = open(name, O_RDONLY); int fd = g_open(name, O_RDONLY);
if (fd == -1) { if (fd == -1) {
return FALSE; return FALSE;
+2 -1
View File
@@ -24,6 +24,7 @@
#include "config.h" #include "config.h"
#include <glib.h> #include <glib.h>
#include <glib/gstdio.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <stdarg.h> #include <stdarg.h>
@@ -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(filename, FALSE);
g_return_val_if_fail(first_tag, FALSE); g_return_val_if_fail(first_tag, FALSE);
f = fopen(filename, "r"); f = g_fopen(filename, "r");
if (f == NULL) { if (f == NULL) {
return FALSE; return FALSE;
} }
+4 -4
View File
@@ -28,10 +28,10 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <dirent.h> #include <dirent.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <glib.h> #include <glib.h>
#include <glib/gstdio.h>
#include "gnc-engine.h" #include "gnc-engine.h"
#include "sixtp-dom-parsers.h" #include "sixtp-dom-parsers.h"
@@ -58,8 +58,8 @@ files_compare(const gchar* f1, const gchar* f2)
int fd1, fd2; int fd1, fd2;
int amount_read1, amount_read2; int amount_read1, amount_read2;
fd1 = open(f1, O_RDONLY); fd1 = g_open(f1, O_RDONLY);
fd2 = open(f2, O_RDONLY); fd2 = g_open(f2, O_RDONLY);
do do
{ {
@@ -372,7 +372,7 @@ test_files_in_dir(int argc, char **argv, gxpf_callback cb,
{ {
struct stat file_info; struct stat file_info;
const char *to_open = argv[count]; 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); printf("cannot stat %s.\n", to_open);
failure("unable to stat file"); failure("unable to stat file");
+3 -3
View File
@@ -28,7 +28,6 @@
#include "config.h" #include "config.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
@@ -36,6 +35,7 @@
#include <string.h> #include <string.h>
#include <glib.h> #include <glib.h>
#include <glib-object.h> #include <glib-object.h>
#include <glib/gstdio.h>
#include "cashobjects.h" #include "cashobjects.h"
#include "Group.h" #include "Group.h"
@@ -63,9 +63,9 @@ remove_locks(const char *filename)
{ {
to_remove = g_strdup_printf("%s.LCK", 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); g_free(to_remove);
} }
+4 -3
View File
@@ -1,5 +1,6 @@
#include "config.h" #include "config.h"
#include <glib.h> #include <glib.h>
#include <glib/gstdio.h>
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
@@ -153,9 +154,9 @@ main(int argc, char **argv)
struct stat file_info; struct stat file_info;
char* filename; char* filename;
filename = g_strdup_printf("%s/%s", test_dir, next_file); filename = g_build_filename(test_dir, next_file, (gchar*) NULL);
if(stat(filename, &file_info) != 0) if(g_stat(filename, &file_info) != 0)
{ {
failure_args("stat", __FILE__, __LINE__, failure_args("stat", __FILE__, __LINE__,
"couldn't stat file %s: %s", filename, "couldn't stat file %s: %s", filename,
+2 -2
View File
@@ -25,7 +25,7 @@
#include "config.h" #include "config.h"
#include <glib.h> #include <glib.h>
#include <stdio.h> #include <glib/gstdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@@ -274,7 +274,7 @@ test_account(int i, Account *test_act)
} }
unlink(filename1); g_unlink(filename1);
g_free(filename1); g_free(filename1);
xmlFreeNode(test_node); xmlFreeNode(test_node);
} }
+2 -2
View File
@@ -1,8 +1,8 @@
#include "config.h" #include "config.h"
#include <glib.h> #include <glib.h>
#include <glib/gstdio.h>
#include <libguile.h> #include <libguile.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@@ -204,7 +204,7 @@ test_generation(void)
/* sixtp_destroy(parser); */ /* sixtp_destroy(parser); */
} }
unlink(filename1); g_unlink(filename1);
g_free(filename1); g_free(filename1);
gnc_commodity_destroy(ran_com); gnc_commodity_destroy(ran_com);
xmlFreeNode(test_node); xmlFreeNode(test_node);
+2 -2
View File
@@ -25,7 +25,7 @@
#include "config.h" #include "config.h"
#include <glib.h> #include <glib.h>
#include <stdio.h> #include <glib/gstdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@@ -116,7 +116,7 @@ test_db (int i, GNCPriceDB *db)
} }
} }
unlink (filename1); g_unlink (filename1);
g_free (filename1); g_free (filename1);
xmlFreeNode (test_node); xmlFreeNode (test_node);
} }
+2 -2
View File
@@ -25,7 +25,7 @@
#include "config.h" #include "config.h"
#include <glib.h> #include <glib.h>
#include <stdio.h> #include <glib/gstdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@@ -473,7 +473,7 @@ test_transaction(void)
/* sixtp_destroy(parser); */ /* sixtp_destroy(parser); */
} }
unlink(filename1); g_unlink(filename1);
g_free(filename1); g_free(filename1);
really_get_rid_of_transaction(ran_trn); really_get_rid_of_transaction(ran_trn);
xmlFreeNode(test_node); xmlFreeNode(test_node);
+2 -2
View File
@@ -37,7 +37,7 @@
#include "config.h" #include "config.h"
#include <glib.h> #include <glib.h>
#include <stdio.h> #include <glib/gstdio.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
@@ -97,7 +97,7 @@ gnc_key_file_save_to_file (const gchar *filename,
contents = g_key_file_to_data(key_file, NULL, NULL); contents = g_key_file_to_data(key_file, NULL, NULL);
length = strlen(contents); 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 (fd == -1) {
if (error) { if (error) {
*error = g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno), *error = g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno),
+2 -2
View File
@@ -25,7 +25,7 @@
#include <errno.h> #include <errno.h>
#include <glib.h> #include <glib.h>
#include <stdio.h> #include <glib/gstdio.h>
#include <string.h> #include <string.h>
#include "Account.h" #include "Account.h"
@@ -157,7 +157,7 @@ xaccOpenLog (void)
filename = g_strconcat (log_base_name, ".", timestamp, ".log", NULL); filename = g_strconcat (log_base_name, ".", timestamp, ".log", NULL);
trans_log = fopen (filename, "a"); trans_log = g_fopen (filename, "a");
if (!trans_log) { if (!trans_log) {
int norr = errno; int norr = errno;
printf ("Error: xaccOpenLog(): cannot open journal \n" printf ("Error: xaccOpenLog(): cannot open journal \n"
+6 -14
View File
@@ -59,8 +59,6 @@ static QofLogModule log_module = GNC_MOD_BACKEND;
static void static void
MakeHomeDir (void) MakeHomeDir (void)
{ {
int rc;
struct stat statbuf;
const gchar *home; const gchar *home;
char *path; char *path;
char *data; char *data;
@@ -71,19 +69,15 @@ MakeHomeDir (void)
path = g_build_filename(home, ".gnucash", (gchar *)NULL); path = g_build_filename(home, ".gnucash", (gchar *)NULL);
rc = stat (path, &statbuf); if (!g_file_test(path, G_FILE_TEST_EXISTS))
if (rc)
{ {
/* assume that the stat failed only because the dir is absent, /* Go ahead and make it. Don't bother much with checking mkdir
* and not because its read-protected or other error.
* Go ahead and make it. Don't bother much with checking mkdir
* for errors; seems pointless. */ * for errors; seems pointless. */
g_mkdir (path, S_IRWXU); /* perms = S_IRWXU = 0700 */ g_mkdir (path, S_IRWXU); /* perms = S_IRWXU = 0700 */
} }
data = g_build_filename (path, "data", (gchar *)NULL); data = g_build_filename (path, "data", (gchar *)NULL);
rc = stat (data, &statbuf); if (!g_file_test(data, G_FILE_TEST_EXISTS))
if (rc)
g_mkdir (data, S_IRWXU); g_mkdir (data, S_IRWXU);
g_free (path); g_free (path);
@@ -182,7 +176,6 @@ xaccUserPathPathGenerator(char *pathbuf, int which)
char * char *
xaccResolveFilePath (const char * filefrag) xaccResolveFilePath (const char * filefrag)
{ {
struct stat statbuf;
char pathbuf[PATH_MAX]; char pathbuf[PATH_MAX];
pathGenerator gens[4]; pathGenerator gens[4];
char *filefrag_dup; char *filefrag_dup;
@@ -226,8 +219,7 @@ xaccResolveFilePath (const char * filefrag)
{ {
gchar *fullpath = g_build_filename(pathbuf, filefrag, (gchar *)NULL); gchar *fullpath = g_build_filename(pathbuf, filefrag, (gchar *)NULL);
int rc = stat (fullpath, &statbuf); if (g_file_test(fullpath, G_FILE_TEST_IS_REGULAR))
if ((!rc) && (S_ISREG(statbuf.st_mode)))
{ {
return fullpath; return fullpath;
} }
@@ -314,7 +306,7 @@ gnc_validate_directory (const gchar *dirname)
struct stat statbuf; struct stat statbuf;
gint rc; gint rc;
rc = stat (dirname, &statbuf); rc = g_stat (dirname, &statbuf);
if (rc) { if (rc) {
switch (errno) { switch (errno) {
case ENOENT: case ENOENT:
@@ -328,7 +320,7 @@ gnc_validate_directory (const gchar *dirname)
dirname, strerror(errno), errno); dirname, strerror(errno), errno);
exit(1); exit(1);
} }
stat (dirname, &statbuf); g_stat (dirname, &statbuf);
break; break;
case EACCES: case EACCES:
+2 -1
View File
@@ -34,6 +34,7 @@
#include <gnome.h> #include <gnome.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <sys/types.h> #include <sys/types.h>
@@ -138,7 +139,7 @@ druid_gconf_update_path (GError **error)
g_strfreev(lines); g_strfreev(lines);
} }
output = fopen(path_filename, "a"); output = g_fopen(path_filename, "a");
if (output == NULL) { if (output == NULL) {
*error = g_error_new (G_FILE_ERROR, *error = g_error_new (G_FILE_ERROR,
g_file_error_from_errno(errno), g_file_error_from_errno(errno),
+2 -1
View File
@@ -29,6 +29,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <stdlib.h> #include <stdlib.h>
@@ -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 (html != NULL, FALSE);
g_return_val_if_fail (filepath != NULL, FALSE); g_return_val_if_fail (filepath != NULL, FALSE);
fh = fopen (filepath, "w"); fh = g_fopen (filepath, "w");
if (!fh) if (!fh)
return FALSE; return FALSE;
+2 -1
View File
@@ -25,6 +25,7 @@
#include <gnome.h> #include <gnome.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
@@ -202,7 +203,7 @@ gnc_get_ea_locale_dir(const char *top_dir)
i = strlen(locale); i = strlen(locale);
ret = g_build_filename(top_dir, locale, (char *)NULL); ret = g_build_filename(top_dir, locale, (char *)NULL);
while (stat(ret, &buf) != 0) while (g_stat(ret, &buf) != 0)
{ {
i--; i--;
if (i<1) if (i<1)
+2 -2
View File
@@ -23,7 +23,7 @@
//#include "config.h" //#include "config.h"
#include <glib.h> #include <glib.h>
#include <stdio.h> #include <glib/gstdio.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <fcntl.h> #include <fcntl.h>
@@ -175,7 +175,7 @@ int main (int argc, char **argv) {
printf("usage:\n\tcsv2glist fname.csv\n"); printf("usage:\n\tcsv2glist fname.csv\n");
} }
fp = fopen (argv[1], "r"); fp = g_fopen (argv[1], "r");
if (fp == NULL) return 1; if (fp == NULL) return 1;
parsed_csv = gnc_csv_parse(fp); parsed_csv = gnc_csv_parse(fp);
+2 -1
View File
@@ -25,6 +25,7 @@
#include <gnome.h> #include <gnome.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#ifdef HAVE_SYS_WAIT_H #ifdef HAVE_SYS_WAIT_H
@@ -532,7 +533,7 @@ on_aqhbci_button (GtkButton *button,
if (wizard_exists) { if (wizard_exists) {
/* Really check whether the file 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) if ( fd == -1)
wizard_exists = FALSE; wizard_exists = FALSE;
else else
+2 -2
View File
@@ -27,7 +27,7 @@
#include <glib.h> #include <glib.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <stdio.h> #include <glib/gstdio.h>
#include <string.h> #include <string.h>
#include <sys/time.h> #include <sys/time.h>
#include <fcntl.h> #include <fcntl.h>
@@ -169,7 +169,7 @@ void gnc_file_aqbanking_import (const gchar *aqbanking_importername,
DEBUG("Filename found: %s",selected_filename); DEBUG("Filename found: %s",selected_filename);
DEBUG("Opening selected file"); DEBUG("Opening selected file");
dtaus_fd = open(selected_filename, O_RDONLY); dtaus_fd = g_open(selected_filename, O_RDONLY);
if (dtaus_fd == -1) { if (dtaus_fd == -1) {
DEBUG("Could not open file %s", selected_filename); DEBUG("Could not open file %s", selected_filename);
return; return;
@@ -27,7 +27,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <stdio.h> #include <glib/gstdio.h>
#include <string.h> #include <string.h>
#include <sys/time.h> #include <sys/time.h>
#include <libguile.h> #include <libguile.h>
@@ -542,7 +542,7 @@ void gnc_file_log_replay (void)
selected_filename); selected_filename);
} else { } else {
DEBUG("Opening selected file"); DEBUG("Opening selected file");
log_file = fopen(selected_filename, "r"); log_file = g_fopen(selected_filename, "r");
if(!log_file || ferror(log_file)!=0) { if(!log_file || ferror(log_file)!=0) {
int err = errno; int err = errno;
perror("File open failed"); perror("File open failed");
+2 -2
View File
@@ -28,7 +28,7 @@
#endif #endif
#include <glib.h> #include <glib.h>
#include <stdio.h> #include <glib/gstdio.h>
#include <string.h> #include <string.h>
#include "gnc-engine.h" #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); g_return_val_if_fail(*filename, QIF_E_BADARGS);
/* Open the file */ /* Open the file */
fp = fopen(filename, "r"); fp = g_fopen(filename, "r");
if (fp == NULL) if (fp == NULL)
return QIF_E_NOFILE; return QIF_E_NOFILE;
@@ -41,6 +41,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <libguile.h> #include <libguile.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <errno.h> #include <errno.h>
@@ -1312,7 +1313,7 @@ gnc_get_export_filename (SCM choice)
if (!filepath) if (!filepath)
return NULL; return NULL;
rc = stat (filepath, &statbuf); rc = g_stat (filepath, &statbuf);
/* Check for an error that isn't a non-existant file. */ /* Check for an error that isn't a non-existant file. */
if (rc != 0 && errno != ENOENT) if (rc != 0 && errno != ENOENT)