mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Use g_dir_{open,read_name,close}.
Replace opendir, readdir and closedir by their GLib wrappers so that files on Windows will be retrieved with the wide character api. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@15403 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
3eb2abc024
commit
6783775210
@ -235,16 +235,16 @@ static size_t
|
||||
init_from_dir(const char *dirname, unsigned int max_files)
|
||||
{
|
||||
char filename[1024];
|
||||
struct dirent *de;
|
||||
const gchar *de;
|
||||
struct stat stats;
|
||||
size_t total;
|
||||
int result;
|
||||
DIR *dir;
|
||||
GDir *dir;
|
||||
|
||||
if (max_files <= 0)
|
||||
return 0;
|
||||
|
||||
dir = opendir (dirname);
|
||||
dir = g_dir_open(dirname, 0, NULL);
|
||||
if (dir == NULL)
|
||||
return 0;
|
||||
|
||||
@ -252,15 +252,15 @@ init_from_dir(const char *dirname, unsigned int max_files)
|
||||
|
||||
do
|
||||
{
|
||||
de = readdir(dir);
|
||||
de = g_dir_read_name(dir);
|
||||
if (de == NULL)
|
||||
break;
|
||||
|
||||
md5_process_bytes(de->d_name, strlen(de->d_name), &guid_context);
|
||||
total += strlen(de->d_name);
|
||||
md5_process_bytes(de, strlen(de), &guid_context);
|
||||
total += strlen(de);
|
||||
|
||||
result = snprintf(filename, sizeof(filename),
|
||||
"%s/%s", dirname, de->d_name);
|
||||
"%s/%s", dirname, de);
|
||||
if ((result < 0) || (result >= (int)sizeof(filename)))
|
||||
continue;
|
||||
|
||||
@ -273,7 +273,7 @@ init_from_dir(const char *dirname, unsigned int max_files)
|
||||
max_files--;
|
||||
} while (max_files > 0);
|
||||
|
||||
closedir(dir);
|
||||
g_dir_close(dir);
|
||||
|
||||
return total;
|
||||
}
|
||||
|
@ -642,23 +642,18 @@ gnc_file_be_write_to_file(FileBackend *fbe,
|
||||
/* ================================================================= */
|
||||
|
||||
static int
|
||||
gnc_file_be_select_files (const struct dirent *d)
|
||||
gnc_file_be_select_files (const gchar *d)
|
||||
{
|
||||
int len = strlen(d->d_name) - 4;
|
||||
|
||||
if (len <= 0)
|
||||
return(0);
|
||||
|
||||
return((strcmp(d->d_name + len, ".LNK") == 0) ||
|
||||
(strcmp(d->d_name + len, ".xac") == 0) ||
|
||||
(strcmp(d->d_name + len, ".log") == 0));
|
||||
return (g_str_has_suffix(d, ".LNK") ||
|
||||
g_str_has_suffix(d, ".xac") ||
|
||||
g_str_has_suffix(d, ".log"));
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_file_be_remove_old_files(FileBackend *be)
|
||||
{
|
||||
struct dirent *dent;
|
||||
DIR *dir;
|
||||
const gchar *dent;
|
||||
GDir *dir;
|
||||
struct stat lockstatbuf, statbuf;
|
||||
int pathlen;
|
||||
time_t now;
|
||||
@ -684,20 +679,20 @@ gnc_file_be_remove_old_files(FileBackend *be)
|
||||
* directory and then one pass over the 'matching' files. --
|
||||
* warlord@MIT.EDU 2002-05-06
|
||||
*/
|
||||
|
||||
dir = opendir (be->dirname);
|
||||
|
||||
dir = g_dir_open (be->dirname, 0, NULL);
|
||||
if (!dir)
|
||||
return;
|
||||
|
||||
now = time(NULL);
|
||||
while((dent = readdir(dir)) != NULL) {
|
||||
while((dent = g_dir_read_name(dir)) != NULL) {
|
||||
char *name;
|
||||
int len;
|
||||
|
||||
if (gnc_file_be_select_files (dent) == 0)
|
||||
continue;
|
||||
|
||||
name = g_build_filename(be->dirname, dent->d_name, (char*)NULL);
|
||||
name = g_build_filename(be->dirname, dent, (gchar*)NULL);
|
||||
len = strlen(name) - 4;
|
||||
|
||||
/* Is this file associated with the current data file */
|
||||
@ -743,7 +738,7 @@ gnc_file_be_remove_old_files(FileBackend *be)
|
||||
}
|
||||
g_free(name);
|
||||
}
|
||||
closedir (dir);
|
||||
g_dir_close (dir);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -423,24 +423,14 @@ gnc_free_example_account_list(GSList *list)
|
||||
g_slist_free(list);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_directory(const gchar *filename)
|
||||
{
|
||||
struct stat fileinfo;
|
||||
|
||||
stat(filename, &fileinfo);
|
||||
|
||||
return S_ISDIR(fileinfo.st_mode);
|
||||
}
|
||||
|
||||
GSList*
|
||||
gnc_load_example_account_list(QofBook *book, const char *dirname)
|
||||
{
|
||||
GSList *ret;
|
||||
DIR *dir;
|
||||
struct dirent *direntry;
|
||||
GDir *dir;
|
||||
const gchar *direntry;
|
||||
|
||||
dir = opendir(dirname);
|
||||
dir = g_dir_open(dirname, 0, NULL);
|
||||
|
||||
if(dir == NULL)
|
||||
{
|
||||
@ -449,13 +439,14 @@ gnc_load_example_account_list(QofBook *book, const char *dirname)
|
||||
|
||||
ret = NULL;
|
||||
|
||||
for(direntry = readdir(dir); direntry != NULL; direntry = readdir(dir))
|
||||
for(direntry = g_dir_read_name(dir); direntry != NULL;
|
||||
direntry = g_dir_read_name(dir))
|
||||
{
|
||||
gchar *filename;
|
||||
GncExampleAccount *gea;
|
||||
filename = g_strdup_printf("%s/%s", dirname, direntry->d_name);
|
||||
filename = g_build_filename(dirname, direntry, (gchar*) NULL);
|
||||
|
||||
if(!is_directory(filename))
|
||||
if(!g_file_test(filename, G_FILE_TEST_IS_DIR))
|
||||
{
|
||||
gea = gnc_read_example_account(book, filename);
|
||||
|
||||
@ -463,14 +454,16 @@ gnc_load_example_account_list(QofBook *book, const char *dirname)
|
||||
{
|
||||
g_free(filename);
|
||||
gnc_free_example_account_list(ret);
|
||||
g_dir_close(dir);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
ret = g_slist_append(ret, gea);
|
||||
}
|
||||
|
||||
|
||||
g_free(filename);
|
||||
}
|
||||
g_dir_close(dir);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ guile_main (void *closure, int argc, char **argv)
|
||||
{
|
||||
const char *location = getenv("GNC_ACCOUNT_PATH");
|
||||
GSList *list = NULL;
|
||||
DIR *ea_dir;
|
||||
GDir *ea_dir;
|
||||
QofBook *book;
|
||||
|
||||
if (!location)
|
||||
@ -81,37 +81,28 @@ guile_main (void *closure, int argc, char **argv)
|
||||
|
||||
book = qof_book_new ();
|
||||
|
||||
if((ea_dir = opendir(location)) == NULL)
|
||||
if((ea_dir = g_dir_open(location, 0, NULL)) == NULL)
|
||||
{
|
||||
failure("unable to open ea directory");
|
||||
}
|
||||
else
|
||||
{
|
||||
struct dirent *entry;
|
||||
const gchar *entry;
|
||||
|
||||
while((entry = readdir(ea_dir)) != NULL)
|
||||
while((entry = g_dir_read_name(ea_dir)) != NULL)
|
||||
{
|
||||
struct stat file_info;
|
||||
if(strstr(entry->d_name, da_ending) != NULL)
|
||||
if(g_str_has_suffix(entry, da_ending))
|
||||
{
|
||||
char *to_open = g_strdup_printf("%s/%s", location,
|
||||
entry->d_name);
|
||||
if(stat(to_open, &file_info) != 0)
|
||||
gchar *to_open = g_build_filename(location, entry, (gchar*)NULL);
|
||||
if (!g_file_test(to_open, G_FILE_TEST_IS_DIR))
|
||||
{
|
||||
failure("unable to stat file");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!S_ISDIR(file_info.st_mode))
|
||||
{
|
||||
test_load_file(book, to_open);
|
||||
}
|
||||
test_load_file(book, to_open);
|
||||
}
|
||||
g_free(to_open);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(ea_dir);
|
||||
g_dir_close(ea_dir);
|
||||
|
||||
{
|
||||
list = gnc_load_example_account_list(book, location);
|
||||
|
@ -107,7 +107,7 @@ int
|
||||
main (int argc, char ** argv)
|
||||
{
|
||||
const char *location = getenv("GNC_TEST_FILES");
|
||||
DIR *xml2_dir;
|
||||
GDir *xml2_dir;
|
||||
|
||||
g_type_init();
|
||||
qof_init();
|
||||
@ -122,38 +122,29 @@ main (int argc, char ** argv)
|
||||
|
||||
xaccLogDisable();
|
||||
|
||||
if((xml2_dir = opendir(location)) == NULL)
|
||||
if((xml2_dir = g_dir_open(location, 0, NULL)) == NULL)
|
||||
{
|
||||
failure("unable to open xml2 directory");
|
||||
}
|
||||
else
|
||||
{
|
||||
struct dirent *entry;
|
||||
const gchar *entry;
|
||||
|
||||
while((entry = readdir(xml2_dir)) != NULL)
|
||||
while((entry = g_dir_read_name(xml2_dir)) != NULL)
|
||||
{
|
||||
if(strstr(entry->d_name, ".gml2") != NULL)
|
||||
if(g_str_has_suffix(entry, ".gml2"))
|
||||
{
|
||||
struct stat file_info;
|
||||
char *to_open = g_strdup_printf("%s/%s", location,
|
||||
entry->d_name);
|
||||
if(stat(to_open, &file_info) != 0)
|
||||
gchar *to_open = g_build_filename(location, entry, (gchar*)NULL);
|
||||
if(!g_file_test(to_open, G_FILE_TEST_IS_DIR))
|
||||
{
|
||||
failure("unable to stat file");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!S_ISDIR(file_info.st_mode))
|
||||
{
|
||||
test_load_file(to_open);
|
||||
}
|
||||
test_load_file(to_open);
|
||||
}
|
||||
g_free(to_open);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir(xml2_dir);
|
||||
g_dir_close(xml2_dir);
|
||||
|
||||
print_test_results();
|
||||
qof_close();
|
||||
|
@ -134,26 +134,26 @@ test_file(const char *filename)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
DIR *adir;
|
||||
GDir *adir;
|
||||
|
||||
gnc_engine_init(argc, argv);
|
||||
xaccLogDisable();
|
||||
|
||||
if((adir = opendir(test_dir)) == NULL)
|
||||
if((adir = g_dir_open(test_dir, 0, NULL)) == NULL)
|
||||
{
|
||||
failure_args("opendir", __FILE__, __LINE__,
|
||||
failure_args("g_dir_open", __FILE__, __LINE__,
|
||||
"couldn't open dir %s", test_dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
struct dirent *next_file;
|
||||
const gchar *next_file;
|
||||
|
||||
while((next_file = readdir(adir)) != NULL)
|
||||
while((next_file = g_dir_read_name(adir)) != NULL)
|
||||
{
|
||||
struct stat file_info;
|
||||
char* filename;
|
||||
|
||||
filename = g_strdup_printf("%s/%s", test_dir, next_file->d_name);
|
||||
filename = g_strdup_printf("%s/%s", test_dir, next_file);
|
||||
|
||||
if(stat(filename, &file_info) != 0)
|
||||
{
|
||||
@ -187,6 +187,7 @@ main(int argc, char **argv)
|
||||
|
||||
g_free(filename);
|
||||
}
|
||||
g_dir_close(adir);
|
||||
}
|
||||
|
||||
print_test_results();
|
||||
|
@ -198,27 +198,27 @@ gnc_module_system_refresh(void)
|
||||
/* look in each search directory */
|
||||
for(current = search_dirs; current; current = current->next)
|
||||
{
|
||||
DIR *d = opendir(current->data);
|
||||
struct dirent * dent = NULL;
|
||||
GDir *d = g_dir_open(current->data, 0,NULL);
|
||||
const gchar *dent = NULL;
|
||||
char * fullpath = NULL;
|
||||
GNCModuleInfo * info;
|
||||
|
||||
if (!d) continue;
|
||||
|
||||
while ((dent = readdir(d)) != NULL)
|
||||
while ((dent = g_dir_read_name(d)) != NULL)
|
||||
{
|
||||
/* is the file a loadable module? */
|
||||
|
||||
/* Gotcha: On MacOS, G_MODULE_SUFFIX is defined as "so", but if we do
|
||||
* not build clean libtool modules with "-module", we get dynamic
|
||||
* libraries ending on .dylib */
|
||||
if (g_str_has_suffix(dent->d_name, "." G_MODULE_SUFFIX) ||
|
||||
g_str_has_suffix(dent->d_name, ".dylib"))
|
||||
if (g_str_has_suffix(dent, "." G_MODULE_SUFFIX) ||
|
||||
g_str_has_suffix(dent, ".dylib"))
|
||||
{
|
||||
/* get the full path name, then dlopen the library and see
|
||||
* if it has the appropriate symbols to be a gnc_module */
|
||||
fullpath = g_build_filename((const gchar *)(current->data),
|
||||
dent->d_name, (char*)NULL);
|
||||
fullpath = g_build_filename((const gchar *)(current->data),
|
||||
dent, (char*)NULL);
|
||||
info = gnc_module_get_info(fullpath);
|
||||
|
||||
if(info)
|
||||
@ -228,7 +228,7 @@ gnc_module_system_refresh(void)
|
||||
g_free(fullpath);
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
g_dir_close(d);
|
||||
|
||||
}
|
||||
/* free the search dir strings */
|
||||
|
Loading…
Reference in New Issue
Block a user