Commit fe2c9e8b authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

app/app_procs.c app/base/temp-buf.c app/core/gimpmodules.c

2002-02-18  Sven Neumann  <sven@gimp.org>

	* 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.
parent fb8c94c0
2002-02-18 Sven Neumann <sven@gimp.org>
* 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 <sven@gimp.org> 2002-02-18 Sven Neumann <sven@gimp.org>
* configure.in: require latest glib and gtk+ releases (1.3.14). * configure.in: require latest glib and gtk+ releases (1.3.14).
......
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h> #include <time.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
...@@ -3517,12 +3516,10 @@ static gchar * ...@@ -3517,12 +3516,10 @@ static gchar *
plug_in_search_in_path (gchar *search_path, plug_in_search_in_path (gchar *search_path,
gchar *filename) gchar *filename)
{ {
gchar *local_path; gchar *local_path;
gchar *token; gchar *token;
gchar *next_token; gchar *next_token;
gchar *path; gchar *path;
struct stat buf;
gint err;
local_path = g_strdup (search_path); local_path = g_strdup (search_path);
next_token = local_path; next_token = local_path;
...@@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, ...@@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path,
{ {
path = g_build_filename (token, filename, NULL); path = g_build_filename (token, filename, NULL);
err = stat (path, &buf); if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
if (!err && S_ISREG (buf.st_mode))
{ {
token = path; token = path;
break; break;
......
...@@ -21,11 +21,11 @@ ...@@ -21,11 +21,11 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_SYS_PARAM_H #ifdef HAVE_SYS_PARAM_H
#include <sys/param.h> #include <sys/param.h>
#endif #endif
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
...@@ -83,7 +83,6 @@ app_init (gint gimp_argc, ...@@ -83,7 +83,6 @@ app_init (gint gimp_argc,
gchar **gimp_argv) gchar **gimp_argv)
{ {
const gchar *gimp_dir; const gchar *gimp_dir;
struct stat stat_buf;
/* Create an instance of the "Gimp" object which is the root of the /* Create an instance of the "Gimp" object which is the root of the
* core object system * core object system
...@@ -99,7 +98,7 @@ app_init (gint gimp_argc, ...@@ -99,7 +98,7 @@ app_init (gint gimp_argc,
*/ */
gimp_dir = gimp_directory (); 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 */ /* not properly installed */
......
...@@ -25,8 +25,6 @@ ...@@ -25,8 +25,6 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <string.h> #include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <glib-object.h> #include <glib-object.h>
...@@ -622,11 +620,9 @@ generate_unique_filename (void) ...@@ -622,11 +620,9 @@ generate_unique_filename (void)
void void
temp_buf_swap (TempBuf *buf) temp_buf_swap (TempBuf *buf)
{ {
TempBuf *swap; TempBuf *swap;
gchar *filename; gchar *filename;
struct stat stat_buf; FILE *fp;
gint err;
FILE *fp;
if (!buf || buf->swapped) if (!buf || buf->swapped)
return; return;
...@@ -654,15 +650,11 @@ temp_buf_swap (TempBuf *buf) ...@@ -654,15 +650,11 @@ temp_buf_swap (TempBuf *buf)
filename = generate_unique_filename (); filename = generate_unique_filename ();
/* Check if generated filename is valid */ /* Check if generated filename is valid */
err = stat (filename, &stat_buf); if (g_file_test (filename, G_FILE_TEST_IS_DIR))
if (!err)
{ {
if (stat_buf.st_mode & S_IFDIR) g_message ("Error in temp buf caching: \"%s\" is a directory (cannot overwrite)", filename);
{ g_free (filename);
g_message ("Error in temp buf caching: \"%s\" is a directory (cannot overwrite)", filename); return;
g_free (filename);
return;
}
} }
/* Open file for overwrite */ /* Open file for overwrite */
...@@ -698,9 +690,8 @@ temp_buf_swap (TempBuf *buf) ...@@ -698,9 +690,8 @@ temp_buf_swap (TempBuf *buf)
void void
temp_buf_unswap (TempBuf *buf) temp_buf_unswap (TempBuf *buf)
{ {
struct stat stat_buf; FILE *fp;
FILE *fp; gboolean succ = FALSE;
gboolean succ = FALSE;
if (!buf || !buf->swapped) if (!buf || !buf->swapped)
return; return;
...@@ -718,9 +709,7 @@ temp_buf_unswap (TempBuf *buf) ...@@ -718,9 +709,7 @@ temp_buf_unswap (TempBuf *buf)
/* Allocate memory for the buffer's data */ /* Allocate memory for the buffer's data */
buf->data = temp_buf_allocate (buf->width * buf->height * buf->bytes); buf->data = temp_buf_allocate (buf->width * buf->height * buf->bytes);
/* Find out if the filename of the swapped data is an existing file... */ if (g_file_test (buf->filename, G_FILE_TEST_IS_REGULAR))
/* (buf->filname HAS to be != 0 */
if (!stat (buf->filename, &stat_buf))
{ {
if ((fp = fopen (buf->filename, "rb"))) if ((fp = fopen (buf->filename, "rb")))
{ {
...@@ -748,8 +737,6 @@ temp_buf_unswap (TempBuf *buf) ...@@ -748,8 +737,6 @@ temp_buf_unswap (TempBuf *buf)
void void
temp_buf_swap_free (TempBuf *buf) temp_buf_swap_free (TempBuf *buf)
{ {
struct stat stat_buf;
if (!buf->swapped) if (!buf->swapped)
return; return;
...@@ -764,7 +751,7 @@ temp_buf_swap_free (TempBuf *buf) ...@@ -764,7 +751,7 @@ temp_buf_swap_free (TempBuf *buf)
} }
/* Find out if the filename of the swapped data is an existing file... */ /* 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 */ /* Delete the swap file */
unlink (buf->filename); unlink (buf->filename);
......
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
...@@ -359,19 +358,14 @@ gimp_modules_module_on_disk_func (gpointer data, ...@@ -359,19 +358,14 @@ gimp_modules_module_on_disk_func (gpointer data,
GimpModuleInfoObj *module_info; GimpModuleInfoObj *module_info;
GList **kill_list; GList **kill_list;
gint old_on_disk; gint old_on_disk;
struct stat statbuf;
gint ret;
module_info = (GimpModuleInfoObj *) data; module_info = (GimpModuleInfoObj *) data;
kill_list = (GList **) user_data; kill_list = (GList **) user_data;
old_on_disk = module_info->on_disk; old_on_disk = module_info->on_disk;
ret = stat (module_info->fullpath, &statbuf); module_info->on_disk = g_file_test (module_info->fullpath,
if (ret != 0) G_FILE_TEST_IS_REGULAR);
module_info->on_disk = FALSE;
else
module_info->on_disk = TRUE;
/* if it's not on the disk, and it isn't in memory, mark it to be /* if it's not on the disk, and it isn't in memory, mark it to be
* removed later. * removed later.
......
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
...@@ -359,19 +358,14 @@ gimp_modules_module_on_disk_func (gpointer data, ...@@ -359,19 +358,14 @@ gimp_modules_module_on_disk_func (gpointer data,
GimpModuleInfoObj *module_info; GimpModuleInfoObj *module_info;
GList **kill_list; GList **kill_list;
gint old_on_disk; gint old_on_disk;
struct stat statbuf;
gint ret;
module_info = (GimpModuleInfoObj *) data; module_info = (GimpModuleInfoObj *) data;
kill_list = (GList **) user_data; kill_list = (GList **) user_data;
old_on_disk = module_info->on_disk; old_on_disk = module_info->on_disk;
ret = stat (module_info->fullpath, &statbuf); module_info->on_disk = g_file_test (module_info->fullpath,
if (ret != 0) G_FILE_TEST_IS_REGULAR);
module_info->on_disk = FALSE;
else
module_info->on_disk = TRUE;
/* if it's not on the disk, and it isn't in memory, mark it to be /* if it's not on the disk, and it isn't in memory, mark it to be
* removed later. * removed later.
......
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h> #include <time.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
...@@ -3517,12 +3516,10 @@ static gchar * ...@@ -3517,12 +3516,10 @@ static gchar *
plug_in_search_in_path (gchar *search_path, plug_in_search_in_path (gchar *search_path,
gchar *filename) gchar *filename)
{ {
gchar *local_path; gchar *local_path;
gchar *token; gchar *token;
gchar *next_token; gchar *next_token;
gchar *path; gchar *path;
struct stat buf;
gint err;
local_path = g_strdup (search_path); local_path = g_strdup (search_path);
next_token = local_path; next_token = local_path;
...@@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, ...@@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path,
{ {
path = g_build_filename (token, filename, NULL); path = g_build_filename (token, filename, NULL);
err = stat (path, &buf); if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
if (!err && S_ISREG (buf.st_mode))
{ {
token = path; token = path;
break; break;
......
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h> #include <time.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
...@@ -3517,12 +3516,10 @@ static gchar * ...@@ -3517,12 +3516,10 @@ static gchar *
plug_in_search_in_path (gchar *search_path, plug_in_search_in_path (gchar *search_path,
gchar *filename) gchar *filename)
{ {
gchar *local_path; gchar *local_path;
gchar *token; gchar *token;
gchar *next_token; gchar *next_token;
gchar *path; gchar *path;
struct stat buf;
gint err;
local_path = g_strdup (search_path); local_path = g_strdup (search_path);
next_token = local_path; next_token = local_path;
...@@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, ...@@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path,
{ {
path = g_build_filename (token, filename, NULL); path = g_build_filename (token, filename, NULL);
err = stat (path, &buf); if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
if (!err && S_ISREG (buf.st_mode))
{ {
token = path; token = path;
break; break;
......
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h> #include <time.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
...@@ -3517,12 +3516,10 @@ static gchar * ...@@ -3517,12 +3516,10 @@ static gchar *
plug_in_search_in_path (gchar *search_path, plug_in_search_in_path (gchar *search_path,
gchar *filename) gchar *filename)
{ {
gchar *local_path; gchar *local_path;
gchar *token; gchar *token;
gchar *next_token; gchar *next_token;
gchar *path; gchar *path;
struct stat buf;
gint err;
local_path = g_strdup (search_path); local_path = g_strdup (search_path);
next_token = local_path; next_token = local_path;
...@@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, ...@@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path,
{ {
path = g_build_filename (token, filename, NULL); path = g_build_filename (token, filename, NULL);
err = stat (path, &buf); if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
if (!err && S_ISREG (buf.st_mode))
{ {
token = path; token = path;
break; break;
......
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h> #include <time.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
...@@ -3517,12 +3516,10 @@ static gchar * ...@@ -3517,12 +3516,10 @@ static gchar *
plug_in_search_in_path (gchar *search_path, plug_in_search_in_path (gchar *search_path,
gchar *filename) gchar *filename)
{ {
gchar *local_path; gchar *local_path;
gchar *token; gchar *token;
gchar *next_token; gchar *next_token;
gchar *path; gchar *path;
struct stat buf;
gint err;
local_path = g_strdup (search_path); local_path = g_strdup (search_path);
next_token = local_path; next_token = local_path;
...@@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, ...@@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path,
{ {
path = g_build_filename (token, filename, NULL); path = g_build_filename (token, filename, NULL);
err = stat (path, &buf); if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
if (!err && S_ISREG (buf.st_mode))
{ {
token = path; token = path;
break; break;
......
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h> #include <time.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
...@@ -3517,12 +3516,10 @@ static gchar * ...@@ -3517,12 +3516,10 @@ static gchar *
plug_in_search_in_path (gchar *search_path, plug_in_search_in_path (gchar *search_path,
gchar *filename) gchar *filename)
{ {
gchar *local_path; gchar *local_path;
gchar *token; gchar *token;
gchar *next_token; gchar *next_token;
gchar *path; gchar *path;
struct stat buf;
gint err;
local_path = g_strdup (search_path); local_path = g_strdup (search_path);
next_token = local_path; next_token = local_path;
...@@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, ...@@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path,
{ {
path = g_build_filename (token, filename, NULL); path = g_build_filename (token, filename, NULL);
err = stat (path, &buf); if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
if (!err && S_ISREG (buf.st_mode))
{ {
token = path; token = path;
break; break;
......
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h> #include <time.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
...@@ -3517,12 +3516,10 @@ static gchar * ...@@ -3517,12 +3516,10 @@ static gchar *
plug_in_search_in_path (gchar *search_path, plug_in_search_in_path (gchar *search_path,
gchar *filename) gchar *filename)
{ {
gchar *local_path; gchar *local_path;
gchar *token; gchar *token;
gchar *next_token; gchar *next_token;
gchar *path; gchar *path;
struct stat buf;
gint err;
local_path = g_strdup (search_path); local_path = g_strdup (search_path);
next_token = local_path; next_token = local_path;
...@@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path, ...@@ -3532,8 +3529,7 @@ plug_in_search_in_path (gchar *search_path,
{ {
path = g_build_filename (token, filename, NULL); path = g_build_filename (token, filename, NULL);
err = stat (path, &buf); if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
if (!err && S_ISREG (buf.st_mode))
{ {
token = path; token = path;
break; break;
......
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h> #include <time.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
...@@ -3517,12 +3516,10 @@ static gchar * ...@@ -3517,12 +3516,10 @@ static gchar *
plug_in_search_in_path (gchar *search_path, plug_in_search_in_path (gchar *search_path,
gchar *filename) gchar *filename)
{ {
gchar *local_path; gchar *local_path;
gchar *token; gchar *token;