diff --git a/ChangeLog b/ChangeLog index 0c1575725c..2bb63c2b94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2002-02-18 Sven Neumann + + * app/app_procs.c + * app/base/temp-buf.c + * app/core/gimpmodules.c + * app/plug-in/plug-in.c + * libgimpbase/gimpenv.c + * libgimpwidgets/gimpfileselection.c + * plug-ins/FractalExplorer/Dialogs.c + * plug-ins/FractalExplorer/FractalExplorer.c + * plug-ins/flame/flame.c + * plug-ins/gfig/gfig.c + * plug-ins/gflare/gflare.c + * plug-ins/gimpressionist/gimpressionist.[ch]: use g_file_test() + instead of stat() whereever possible. Improves code readability. + 2002-02-18 Sven Neumann * configure.in: require latest glib and gtk+ releases (1.3.14). diff --git a/app/actions/plug-in-commands.c b/app/actions/plug-in-commands.c index 782795de36..3182a03528 100644 --- a/app/actions/plug-in-commands.c +++ b/app/actions/plug-in-commands.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/app/app_procs.c b/app/app_procs.c index 65baf42cd5..c0e6ba91f9 100644 --- a/app/app_procs.c +++ b/app/app_procs.c @@ -21,11 +21,11 @@ #include #include #include + #ifdef HAVE_SYS_PARAM_H #include #endif -#include -#include + #ifdef HAVE_UNISTD_H #include #endif @@ -83,7 +83,6 @@ app_init (gint gimp_argc, gchar **gimp_argv) { const gchar *gimp_dir; - struct stat stat_buf; /* Create an instance of the "Gimp" object which is the root of the * core object system @@ -99,7 +98,7 @@ app_init (gint gimp_argc, */ gimp_dir = gimp_directory (); - if (stat (gimp_dir, &stat_buf) != 0) + if (!g_file_test (gimp_dir, G_FILE_TEST_IS_DIR)) { /* not properly installed */ diff --git a/app/base/temp-buf.c b/app/base/temp-buf.c index 22dd3f2682..180af6e35d 100644 --- a/app/base/temp-buf.c +++ b/app/base/temp-buf.c @@ -25,8 +25,6 @@ #include #endif #include -#include -#include #include @@ -622,11 +620,9 @@ generate_unique_filename (void) void temp_buf_swap (TempBuf *buf) { - TempBuf *swap; - gchar *filename; - struct stat stat_buf; - gint err; - FILE *fp; + TempBuf *swap; + gchar *filename; + FILE *fp; if (!buf || buf->swapped) return; @@ -654,15 +650,11 @@ temp_buf_swap (TempBuf *buf) filename = generate_unique_filename (); /* Check if generated filename is valid */ - err = stat (filename, &stat_buf); - if (!err) + if (g_file_test (filename, G_FILE_TEST_IS_DIR)) { - if (stat_buf.st_mode & S_IFDIR) - { - g_message ("Error in temp buf caching: \"%s\" is a directory (cannot overwrite)", filename); - g_free (filename); - return; - } + g_message ("Error in temp buf caching: \"%s\" is a directory (cannot overwrite)", filename); + g_free (filename); + return; } /* Open file for overwrite */ @@ -698,9 +690,8 @@ temp_buf_swap (TempBuf *buf) void temp_buf_unswap (TempBuf *buf) { - struct stat stat_buf; - FILE *fp; - gboolean succ = FALSE; + FILE *fp; + gboolean succ = FALSE; if (!buf || !buf->swapped) return; @@ -718,9 +709,7 @@ temp_buf_unswap (TempBuf *buf) /* Allocate memory for the buffer's data */ buf->data = temp_buf_allocate (buf->width * buf->height * buf->bytes); - /* Find out if the filename of the swapped data is an existing file... */ - /* (buf->filname HAS to be != 0 */ - if (!stat (buf->filename, &stat_buf)) + if (g_file_test (buf->filename, G_FILE_TEST_IS_REGULAR)) { if ((fp = fopen (buf->filename, "rb"))) { @@ -748,8 +737,6 @@ temp_buf_unswap (TempBuf *buf) void temp_buf_swap_free (TempBuf *buf) { - struct stat stat_buf; - if (!buf->swapped) return; @@ -764,7 +751,7 @@ temp_buf_swap_free (TempBuf *buf) } /* Find out if the filename of the swapped data is an existing file... */ - if (!stat (buf->filename, &stat_buf)) + if (g_file_test (buf->filename, G_FILE_TEST_IS_REGULAR)) { /* Delete the swap file */ unlink (buf->filename); diff --git a/app/core/gimp-modules.c b/app/core/gimp-modules.c index 657843d15b..392f2bc4d3 100644 --- a/app/core/gimp-modules.c +++ b/app/core/gimp-modules.c @@ -23,8 +23,7 @@ #include #include -#include -#include + #ifdef HAVE_UNISTD_H #include #endif @@ -359,19 +358,14 @@ gimp_modules_module_on_disk_func (gpointer data, GimpModuleInfoObj *module_info; GList **kill_list; gint old_on_disk; - struct stat statbuf; - gint ret; module_info = (GimpModuleInfoObj *) data; kill_list = (GList **) user_data; old_on_disk = module_info->on_disk; - ret = stat (module_info->fullpath, &statbuf); - if (ret != 0) - module_info->on_disk = FALSE; - else - module_info->on_disk = TRUE; + module_info->on_disk = g_file_test (module_info->fullpath, + G_FILE_TEST_IS_REGULAR); /* if it's not on the disk, and it isn't in memory, mark it to be * removed later. diff --git a/app/core/gimpmodules.c b/app/core/gimpmodules.c index 657843d15b..392f2bc4d3 100644 --- a/app/core/gimpmodules.c +++ b/app/core/gimpmodules.c @@ -23,8 +23,7 @@ #include #include -#include -#include + #ifdef HAVE_UNISTD_H #include #endif @@ -359,19 +358,14 @@ gimp_modules_module_on_disk_func (gpointer data, GimpModuleInfoObj *module_info; GList **kill_list; gint old_on_disk; - struct stat statbuf; - gint ret; module_info = (GimpModuleInfoObj *) data; kill_list = (GList **) user_data; old_on_disk = module_info->on_disk; - ret = stat (module_info->fullpath, &statbuf); - if (ret != 0) - module_info->on_disk = FALSE; - else - module_info->on_disk = TRUE; + module_info->on_disk = g_file_test (module_info->fullpath, + G_FILE_TEST_IS_REGULAR); /* if it's not on the disk, and it isn't in memory, mark it to be * removed later. diff --git a/app/gui/plug-in-commands.c b/app/gui/plug-in-commands.c index 782795de36..3182a03528 100644 --- a/app/gui/plug-in-commands.c +++ b/app/gui/plug-in-commands.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/app/gui/plug-in-menus.c b/app/gui/plug-in-menus.c index 782795de36..3182a03528 100644 --- a/app/gui/plug-in-menus.c +++ b/app/gui/plug-in-menus.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/app/menus/plug-in-menus.c b/app/menus/plug-in-menus.c index 782795de36..3182a03528 100644 --- a/app/menus/plug-in-menus.c +++ b/app/menus/plug-in-menus.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/app/plug-in/gimpplugin-message.c b/app/plug-in/gimpplugin-message.c index 782795de36..3182a03528 100644 --- a/app/plug-in/gimpplugin-message.c +++ b/app/plug-in/gimpplugin-message.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/app/plug-in/gimpplugin-progress.c b/app/plug-in/gimpplugin-progress.c index 782795de36..3182a03528 100644 --- a/app/plug-in/gimpplugin-progress.c +++ b/app/plug-in/gimpplugin-progress.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/app/plug-in/gimpplugin.c b/app/plug-in/gimpplugin.c index 782795de36..3182a03528 100644 --- a/app/plug-in/gimpplugin.c +++ b/app/plug-in/gimpplugin.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/app/plug-in/gimppluginmanager-call.c b/app/plug-in/gimppluginmanager-call.c index 782795de36..3182a03528 100644 --- a/app/plug-in/gimppluginmanager-call.c +++ b/app/plug-in/gimppluginmanager-call.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/app/plug-in/gimppluginmanager-run.c b/app/plug-in/gimppluginmanager-run.c index 782795de36..3182a03528 100644 --- a/app/plug-in/gimppluginmanager-run.c +++ b/app/plug-in/gimppluginmanager-run.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/app/plug-in/gimppluginmanager.c b/app/plug-in/gimppluginmanager.c index 782795de36..3182a03528 100644 --- a/app/plug-in/gimppluginmanager.c +++ b/app/plug-in/gimppluginmanager.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/app/plug-in/gimppluginshm.c b/app/plug-in/gimppluginshm.c index 782795de36..3182a03528 100644 --- a/app/plug-in/gimppluginshm.c +++ b/app/plug-in/gimppluginshm.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/app/plug-in/plug-in-def.c b/app/plug-in/plug-in-def.c index 782795de36..3182a03528 100644 --- a/app/plug-in/plug-in-def.c +++ b/app/plug-in/plug-in-def.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/app/plug-in/plug-in-message.c b/app/plug-in/plug-in-message.c index 782795de36..3182a03528 100644 --- a/app/plug-in/plug-in-message.c +++ b/app/plug-in/plug-in-message.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/app/plug-in/plug-in-params.c b/app/plug-in/plug-in-params.c index 782795de36..3182a03528 100644 --- a/app/plug-in/plug-in-params.c +++ b/app/plug-in/plug-in-params.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/app/plug-in/plug-in-progress.c b/app/plug-in/plug-in-progress.c index 782795de36..3182a03528 100644 --- a/app/plug-in/plug-in-progress.c +++ b/app/plug-in/plug-in-progress.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/app/plug-in/plug-in-run.c b/app/plug-in/plug-in-run.c index 782795de36..3182a03528 100644 --- a/app/plug-in/plug-in-run.c +++ b/app/plug-in/plug-in-run.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/app/plug-in/plug-in-shm.c b/app/plug-in/plug-in-shm.c index 782795de36..3182a03528 100644 --- a/app/plug-in/plug-in-shm.c +++ b/app/plug-in/plug-in-shm.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/app/plug-in/plug-in.c b/app/plug-in/plug-in.c index 782795de36..3182a03528 100644 --- a/app/plug-in/plug-in.c +++ b/app/plug-in/plug-in.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/app/plug-in/plug-ins.c b/app/plug-in/plug-ins.c index 782795de36..3182a03528 100644 --- a/app/plug-in/plug-ins.c +++ b/app/plug-in/plug-ins.c @@ -33,8 +33,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif -#include -#include + #include #ifdef HAVE_UNISTD_H #include @@ -3517,12 +3516,10 @@ static gchar * plug_in_search_in_path (gchar *search_path, gchar *filename) { - gchar *local_path; - gchar *token; - gchar *next_token; - gchar *path; - struct stat buf; - gint err; + gchar *local_path; + gchar *token; + gchar *next_token; + gchar *path; local_path = g_strdup (search_path); next_token = local_path; @@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, { path = g_build_filename (token, filename, NULL); - err = stat (path, &buf); - if (!err && S_ISREG (buf.st_mode)) + if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) { token = path; break; diff --git a/libgimpbase/gimpenv.c b/libgimpbase/gimpenv.c index 177de84c2d..7bf27b0dc2 100644 --- a/libgimpbase/gimpenv.c +++ b/libgimpbase/gimpenv.c @@ -23,9 +23,11 @@ #include "config.h" #include + #include #include #include + #ifdef HAVE_UNISTD_H #include #endif @@ -287,9 +289,7 @@ gimp_path_parse (const gchar *path, GList *list = NULL; GList *fail_list = NULL; gint i; - - struct stat filestat; - gint err = FALSE; + gboolean exists = TRUE; if (!path || !*path || max_paths < 1 || max_paths > 256) return NULL; @@ -321,11 +321,10 @@ gimp_path_parse (const gchar *path, _fnslashify (dir); #endif - /* check if directory exists */ if (check) - err = stat (dir->str, &filestat); + exists = g_file_test (dir->str, G_FILE_TEST_IS_DIR); - if (!err) + if (exists) list = g_list_prepend (list, g_strdup (dir->str)); else if (check_failed) fail_list = g_list_prepend (fail_list, g_strdup (dir->str)); diff --git a/libgimpmodule/gimpmoduledb.c b/libgimpmodule/gimpmoduledb.c index 657843d15b..392f2bc4d3 100644 --- a/libgimpmodule/gimpmoduledb.c +++ b/libgimpmodule/gimpmoduledb.c @@ -23,8 +23,7 @@ #include #include -#include -#include + #ifdef HAVE_UNISTD_H #include #endif @@ -359,19 +358,14 @@ gimp_modules_module_on_disk_func (gpointer data, GimpModuleInfoObj *module_info; GList **kill_list; gint old_on_disk; - struct stat statbuf; - gint ret; module_info = (GimpModuleInfoObj *) data; kill_list = (GList **) user_data; old_on_disk = module_info->on_disk; - ret = stat (module_info->fullpath, &statbuf); - if (ret != 0) - module_info->on_disk = FALSE; - else - module_info->on_disk = TRUE; + module_info->on_disk = g_file_test (module_info->fullpath, + G_FILE_TEST_IS_REGULAR); /* if it's not on the disk, and it isn't in memory, mark it to be * removed later. diff --git a/libgimpwidgets/gimpfileentry.c b/libgimpwidgets/gimpfileentry.c index b5972cbf48..67b12a214a 100644 --- a/libgimpwidgets/gimpfileentry.c +++ b/libgimpwidgets/gimpfileentry.c @@ -411,8 +411,8 @@ gimp_file_selection_browse_callback (GtkWidget *widget, static void gimp_file_selection_check_filename (GimpFileSelection *gfs) { - static struct stat statbuf; - gchar *filename; + gchar *filename; + gboolean exists; if (! gfs->check_valid) return; @@ -422,17 +422,14 @@ gimp_file_selection_check_filename (GimpFileSelection *gfs) filename = gtk_editable_get_chars (GTK_EDITABLE (gfs->entry), 0, -1); - if ((stat (filename, &statbuf) == 0) && - (gfs->dir_only ? S_ISDIR (statbuf.st_mode) : S_ISREG (statbuf.st_mode))) - { - gtk_image_set_from_stock (GTK_IMAGE (gfs->file_exists), - GTK_STOCK_YES, GTK_ICON_SIZE_BUTTON); - } + if (gfs->dir_only) + exists = g_file_test (filename, G_FILE_TEST_IS_DIR); else - { - gtk_image_set_from_stock (GTK_IMAGE (gfs->file_exists), - GTK_STOCK_NO, GTK_ICON_SIZE_BUTTON); - } + exists = g_file_test (filename, G_FILE_TEST_IS_REGULAR); g_free (filename); + + gtk_image_set_from_stock (GTK_IMAGE (gfs->file_exists), + exists ? GTK_STOCK_YES : GTK_STOCK_NO, + GTK_ICON_SIZE_BUTTON); } diff --git a/libgimpwidgets/gimpfileselection.c b/libgimpwidgets/gimpfileselection.c index b5972cbf48..67b12a214a 100644 --- a/libgimpwidgets/gimpfileselection.c +++ b/libgimpwidgets/gimpfileselection.c @@ -411,8 +411,8 @@ gimp_file_selection_browse_callback (GtkWidget *widget, static void gimp_file_selection_check_filename (GimpFileSelection *gfs) { - static struct stat statbuf; - gchar *filename; + gchar *filename; + gboolean exists; if (! gfs->check_valid) return; @@ -422,17 +422,14 @@ gimp_file_selection_check_filename (GimpFileSelection *gfs) filename = gtk_editable_get_chars (GTK_EDITABLE (gfs->entry), 0, -1); - if ((stat (filename, &statbuf) == 0) && - (gfs->dir_only ? S_ISDIR (statbuf.st_mode) : S_ISREG (statbuf.st_mode))) - { - gtk_image_set_from_stock (GTK_IMAGE (gfs->file_exists), - GTK_STOCK_YES, GTK_ICON_SIZE_BUTTON); - } + if (gfs->dir_only) + exists = g_file_test (filename, G_FILE_TEST_IS_DIR); else - { - gtk_image_set_from_stock (GTK_IMAGE (gfs->file_exists), - GTK_STOCK_NO, GTK_ICON_SIZE_BUTTON); - } + exists = g_file_test (filename, G_FILE_TEST_IS_REGULAR); g_free (filename); + + gtk_image_set_from_stock (GTK_IMAGE (gfs->file_exists), + exists ? GTK_STOCK_YES : GTK_STOCK_NO, + GTK_ICON_SIZE_BUTTON); } diff --git a/plug-ins/FractalExplorer/Dialogs.c b/plug-ins/FractalExplorer/Dialogs.c index 182bd6a7a5..becc9c8f7e 100644 --- a/plug-ins/FractalExplorer/Dialogs.c +++ b/plug-ins/FractalExplorer/Dialogs.c @@ -3,8 +3,6 @@ #include #include #include -#include -#include #ifdef __GNUC__ #warning GTK_DISABLE_DEPRECATED @@ -1612,8 +1610,6 @@ file_selection_ok (GtkWidget *w, gpointer data) { const gchar *filenamebuf; - struct stat filestat; - gint err; filenamebuf = gtk_file_selection_get_filename (GTK_FILE_SELECTION(fs)); @@ -1624,10 +1620,7 @@ file_selection_ok (GtkWidget *w, return; } - /* Check if directory exists */ - err = stat (filenamebuf, &filestat); - - if (!err && S_ISDIR (filestat.st_mode)) + if (g_file_test (filenamebuf, G_FILE_TEST_IS_DIR)) { /* Can't save to directory */ g_message (_("Save: Can't save to a folder.")); @@ -1648,14 +1641,10 @@ load_file_selection_ok (GtkWidget *w, GtkFileSelection *fs, gpointer data) { - struct stat filestat; - gint err; + filename = + g_strdup (gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs))); - filename = g_strdup (gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs))); - - err = stat (filename, &filestat); - - if (!err && S_ISREG (filestat.st_mode)) + if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { explorer_load (); } diff --git a/plug-ins/FractalExplorer/FractalExplorer.c b/plug-ins/FractalExplorer/FractalExplorer.c index 21815937be..ec73c7f6a8 100644 --- a/plug-ins/FractalExplorer/FractalExplorer.c +++ b/plug-ins/FractalExplorer/FractalExplorer.c @@ -54,12 +54,9 @@ #include #include #include -#include -#include #ifdef HAVE_UNISTD_H #include #endif -#include #ifdef __GNUC__ #warning GTK_DISABLE_DEPRECATED @@ -151,13 +148,13 @@ static void build_list_items (GtkWidget *list); static void fractalexplorer_free (fractalexplorerOBJ *feOBJ); static void fractalexplorer_free_everything (fractalexplorerOBJ *feOBJ); static void fractalexplorer_list_free_all (void); -static fractalexplorerOBJ * fractalexplorer_load (gchar *filename, - gchar *name); +static fractalexplorerOBJ * fractalexplorer_load (const gchar *filename, + const gchar *name); -static void fractalexplorer_list_load_all (GList *plist); -static void fractalexplorer_rescan_ok_callback (GtkWidget *widget, - gpointer data); -static void fractalexplorer_rescan_list (void); +static void fractalexplorer_list_load_all (GList *plist); +static void fractalexplorer_rescan_ok_callback (GtkWidget *widget, + gpointer data); +static void fractalexplorer_rescan_list (void); GimpPlugInInfo PLUG_IN_INFO = @@ -1228,8 +1225,8 @@ fractalexplorer_list_free_all (void) } fractalexplorerOBJ * -fractalexplorer_load (gchar *filename, - gchar *name) +fractalexplorer_load (const gchar *filename, + const gchar *name) { fractalexplorerOBJ * fractalexplorer; FILE * fp; @@ -1292,8 +1289,6 @@ fractalexplorer_list_load_all (GList *plist) gchar *filename; GDir *dir; const gchar *dir_ent; - struct stat filestat; - gint err; /* Make sure to clear any existing fractalexplorers */ current_obj = pic_obj = NULL; @@ -1317,18 +1312,14 @@ fractalexplorer_list_load_all (GList *plist) { filename = g_build_filename (path, dir_ent, NULL); - /* Check the file and see that it is not a sub-directory */ - err = stat (filename, &filestat); - - if (!err && S_ISREG (filestat.st_mode)) + if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { - fractalexplorer = fractalexplorer_load (filename, dir_ent); if (fractalexplorer) { /* Read only ?*/ - if(access(filename,W_OK)) + if (access (filename, W_OK)) fractalexplorer->obj_status |= fractalexplorer_READONLY; fractalexplorer_list_insert (fractalexplorer); diff --git a/plug-ins/flame/flame.c b/plug-ins/flame/flame.c index 458337c0f1..94ef3d382e 100644 --- a/plug-ins/flame/flame.c +++ b/plug-ins/flame/flame.c @@ -24,11 +24,11 @@ #include #include -#include -#include + #ifdef HAVE_UNISTD_H #include #endif + #include #include #include @@ -409,7 +409,6 @@ file_ok_callback (GtkWidget *widget, { GtkFileSelection *fs; const gchar *filename; - struct stat filestat; fs = GTK_FILE_SELECTION (data); filename = gtk_file_selection_get_filename (fs); @@ -420,15 +419,9 @@ file_ok_callback (GtkWidget *widget, gint i, c; gchar *ss; - if (stat (filename, &filestat)) + if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { - g_message ("%s: %s", filename, g_strerror (errno)); - return; - } - - if (! S_ISREG (filestat.st_mode)) - { - g_message (_("%s: Is not a regular file"), filename); + g_message (_("'%s' is not a regular file"), filename); return; } @@ -436,7 +429,7 @@ file_ok_callback (GtkWidget *widget, if (f == NULL) { - g_message ("%s: %s", filename, g_strerror (errno)); + g_message (_("Can't open '%s': %s"), filename, g_strerror (errno)); return; } diff --git a/plug-ins/gfig/gfig.c b/plug-ins/gfig/gfig.c index a306f43a08..d9127e8d81 100644 --- a/plug-ins/gfig/gfig.c +++ b/plug-ins/gfig/gfig.c @@ -52,13 +52,12 @@ #include #include -#include -#include + #ifdef HAVE_UNISTD_H #include #endif + #include -#include #ifdef __GNUC__ #warning GTK_DISABLE_DEPRECATED @@ -865,7 +864,7 @@ gfig_name_encode (gchar *dest, while (*src && cnt--) { - if (iscntrl (*src) || isspace (*src) || *src == '\\') + if (g_ascii_iscntrl (*src) || g_ascii_isspace (*src) || *src == '\\') { sprintf (dest, "\\%03o", *src++); dest += 4; @@ -1006,8 +1005,6 @@ gfig_list_load_all (GList *plist) gchar *filename; GDir *dir; const gchar *dir_ent; - struct stat filestat; - gint err; /* Make sure to clear any existing gfigs */ current_obj = pic_obj = NULL; @@ -1031,9 +1028,7 @@ gfig_list_load_all (GList *plist) filename = g_build_filename (path, dir_ent, NULL); /* Check the file and see that it is not a sub-directory */ - err = stat (filename, &filestat); - - if (!err && S_ISREG (filestat.st_mode)) + if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { gfig = gfig_load (filename, dir_ent); @@ -1517,8 +1512,6 @@ file_selection_ok (GtkWidget *w, gpointer data) { const gchar *filenamebuf; - struct stat filestat; - gint err; GFigObj *obj = (GFigObj *)gtk_object_get_user_data (GTK_OBJECT (fs)); GFigObj *real_current; @@ -1534,10 +1527,7 @@ file_selection_ok (GtkWidget *w, return; } - /* Check if directory exists */ - err = stat (filenamebuf, &filestat); - - if (!err && S_ISDIR (filestat.st_mode)) + if (g_file_test (filenamebuf, G_FILE_TEST_IS_DIR)) { g_message ("Save: Can't save to a folder."); return; @@ -4570,8 +4560,6 @@ gfig_load_file_selection_ok (GtkWidget *widget, gpointer data) { const gchar *filename; - struct stat filestat; - gint err; GFigObj *gfig; GFigObj *current_saved; @@ -4581,9 +4569,7 @@ gfig_load_file_selection_ok (GtkWidget *widget, printf ("Loading file '%s'\n", filename); #endif /* DEBUG */ - err = stat (filename, &filestat); - - if (!err && S_ISREG (filestat.st_mode)) + if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { /* Hack - current object MUST be NULL to prevent setup_undo () * from kicking in. diff --git a/plug-ins/gflare/gflare.c b/plug-ins/gflare/gflare.c index 7daa135c10..1ddded6511 100644 --- a/plug-ins/gflare/gflare.c +++ b/plug-ins/gflare/gflare.c @@ -1806,8 +1806,6 @@ gflares_list_load_all (void) gchar *filename; GDir *dir; const gchar *dir_ent; - struct stat filestat; - gint err; #if 0 /* @@@ */ printf("Waiting... (pid %d)\n", getpid()); @@ -1835,9 +1833,7 @@ gflares_list_load_all (void) filename = g_build_filename (path, dir_ent, NULL); /* Check the file and see that it is not a sub-directory */ - err = stat (filename, &filestat); - - if (!err && S_ISREG (filestat.st_mode)) + if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { gflare = gflare_load (filename, dir_ent); if (gflare) diff --git a/plug-ins/gimpressionist/gimpressionist.c b/plug-ins/gimpressionist/gimpressionist.c index 20cba6daab..525e7dce82 100644 --- a/plug-ins/gimpressionist/gimpressionist.c +++ b/plug-ins/gimpressionist/gimpressionist.c @@ -8,8 +8,6 @@ #include #include #include -#include -#include #ifdef HAVE_UNISTD_H #include #endif @@ -45,7 +43,6 @@ GList * parsepath (void) { static GList *lastpath = NULL; gchar *gimpdatasubdir, *defaultpath, *tmps; - struct stat st; if (lastpath) return lastpath; @@ -66,18 +63,25 @@ GList * parsepath (void) if (!tmps) { - if (stat (gimpdatasubdir, &st) != 0 - || !S_ISDIR(st.st_mode)) + if (!g_file_test (gimpdatasubdir, G_FILE_TEST_IS_DIR)) { /* No gimpressionist-path parameter, - * and the default doesn't exist */ - g_message( "*** Warning ***\n" - "It is highly recommended to add\n" - " (gimpressionist-path \"${gimp_dir}" G_DIR_SEPARATOR_S "gimpressionist" - G_SEARCHPATH_SEPARATOR_S - "${gimp_data_dir}" G_DIR_SEPARATOR_S "gimpressionist\")\n" - "(or similar) to your gimprc file.\n"); - } + and the default doesn't exist */ + gchar *path = g_strconcat ("${gimp_dir}", + G_DIR_SEPARATOR_S, + "gimpressionist", + G_SEARCHPATH_SEPARATOR_S, + "${gimp_data_dir}", + G_DIR_SEPARATOR_S, + "gimpressionist", + NULL); + + /* don't translate the gimprc entry */ + g_message (_("It is highly recommended to add\n" + " (gimpressionist-path \"%s\")\n" + "(or similar) to your gimprc file."), path); + g_free (path); + } tmps = g_strdup (defaultpath); } } @@ -89,21 +93,22 @@ GList * parsepath (void) return lastpath; } -gchar *findfile(char *fn) +gchar * +findfile (const gchar *fn) { static GList *rcpath = NULL; GList *thispath; gchar *filename; - struct stat st; - if(!rcpath) rcpath = parsepath (); + if (!rcpath) + rcpath = parsepath (); thispath = rcpath; while (rcpath && thispath) { filename = g_build_filename (thispath->data, fn, NULL); - if(!stat(filename, &st)) + if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) return filename; g_free (filename); thispath = thispath->next; @@ -254,9 +259,8 @@ void reselect(GtkWidget *list, char *fname) void readdirintolist_real(char *subdir, GtkWidget *list, char *selected) { - char *fpath; + gchar *fpath; const gchar *de; - struct stat st; GtkWidget *selectedw = NULL, *tmpw; GDir *dir; GList *flist = NULL; @@ -271,19 +275,28 @@ void readdirintolist_real(char *subdir, GtkWidget *list, char *selected) } } - dir = g_dir_open(subdir, 0, NULL); + dir = g_dir_open (subdir, 0, NULL); - if(!dir) + if (!dir) return; - for(;;) { - if(!(de = g_dir_read_name(dir))) break; - fpath = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", subdir, de); - stat(fpath, &st); - g_free(fpath); - if(!S_ISREG(st.st_mode)) continue; - flist = g_list_insert_sorted(flist, g_strdup(de), (GCompareFunc)g_ascii_strcasecmp); - } + for(;;) + { + gboolean file_exists; + + de = g_dir_read_name (dir); + if (!de) + break; + + fpath = g_build_filename (subdir, de, NULL); + file_exists = g_file_test (fpath, G_FILE_TEST_IS_REGULAR); + g_free (fpath); + + if (!file_exists) + continue; + + flist = g_list_insert_sorted(flist, g_strdup(de), (GCompareFunc)g_ascii_strcasecmp); + } g_dir_close(dir); while(flist) { @@ -307,12 +320,13 @@ void readdirintolist(char *subdir, GtkWidget *list, char *selected) char *tmpdir; GList *thispath = parsepath(); - while(thispath) { - tmpdir = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", (char *)thispath->data, subdir); - readdirintolist_real(tmpdir, list, selected); - g_free(tmpdir); - thispath = thispath->next; - } + while(thispath) + { + tmpdir = g_build_filename ((gchar *) thispath->data, subdir, NULL); + readdirintolist_real (tmpdir, list, selected); + g_free (tmpdir); + thispath = thispath->next; + } } diff --git a/plug-ins/gimpressionist/gimpressionist.h b/plug-ins/gimpressionist/gimpressionist.h index e0858e30e4..83a1591cb2 100644 --- a/plug-ins/gimpressionist/gimpressionist.h +++ b/plug-ins/gimpressionist/gimpressionist.h @@ -182,7 +182,7 @@ void updatepreviewprev(GtkWidget *wg, void *d); void grabarea(void); void storevals(void); void restorevals(void); -char *findfile(char *); +gchar *findfile(const gchar *); void unselectall(GtkWidget *list); void reselect(GtkWidget *list, char *fname);