mirror of
https://github.com/Gnucash/gnucash.git
synced 2026-09-03 20:53:02 -05:00
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:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <libguile.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <libintl.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
@@ -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 <lockstatbuf.st_mtime))
|
||||
{
|
||||
PINFO ("unlink lock file: %s", name);
|
||||
unlink(name);
|
||||
g_unlink(name);
|
||||
}
|
||||
else if (be->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;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
#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;
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@@ -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;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.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(first_tag, FALSE);
|
||||
|
||||
f = fopen(filename, "r");
|
||||
f = g_fopen(filename, "r");
|
||||
if (f == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -28,10 +28,10 @@
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
|
||||
#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");
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
|
||||
#include "config.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
@@ -36,6 +35,7 @@
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib/gstdio.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "config.h"
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -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,
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -274,7 +274,7 @@ test_account(int i, Account *test_act)
|
||||
}
|
||||
|
||||
|
||||
unlink(filename1);
|
||||
g_unlink(filename1);
|
||||
g_free(filename1);
|
||||
xmlFreeNode(test_node);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <libguile.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -116,7 +116,7 @@ test_db (int i, GNCPriceDB *db)
|
||||
}
|
||||
}
|
||||
|
||||
unlink (filename1);
|
||||
g_unlink (filename1);
|
||||
g_free (filename1);
|
||||
xmlFreeNode (test_node);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.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);
|
||||
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),
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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"
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
|
||||
#include <gnome.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
@@ -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),
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.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 (filepath != NULL, FALSE);
|
||||
|
||||
fh = fopen (filepath, "w");
|
||||
fh = g_fopen (filepath, "w");
|
||||
if (!fh)
|
||||
return FALSE;
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include <gnome.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
@@ -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)
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
//#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
@@ -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);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include <gnome.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#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
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <stdio.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <fcntl.h>
|
||||
@@ -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;
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <stdio.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <libguile.h>
|
||||
@@ -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");
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#endif
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <string.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);
|
||||
|
||||
/* Open the file */
|
||||
fp = fopen(filename, "r");
|
||||
fp = g_fopen(filename, "r");
|
||||
if (fp == NULL)
|
||||
return QIF_E_NOFILE;
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <libguile.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user