applied gimp-entity-980929-1, adds write error handling

* app/temp_buf.c: applied gimp-entity-980929-1, adds write error handling

* app/gimprc.c
* app/install.c
* app/tips_dialog.c: allow use of GIMP_DATADIR to override compiled in default

-Yosh
This commit is contained in:
Manish Singh 1998-10-09 22:44:14 +00:00
parent a814e90236
commit 6ad1ea221a
11 changed files with 117 additions and 30 deletions

View File

@ -1,3 +1,13 @@
Fri Oct 9 15:36:52 PDT 1998 Manish Singh <yosh@gimp.org>
* app/temp_buf.c: applied gimp-entity-980929-1, adds
write error handling
* app/gimprc.c
* app/install.c
* app/tips_dialog.c: allow use of GIMP_DATADIR to override
compiled in default
Tue Oct 6 23:40:22 PDT 1998 Manish Singh <yosh@gimp.org>
* app/interface.c: applied gimp-quinn-981004-0, make the

View File

@ -474,11 +474,21 @@ temp_buf_swap (buf)
/* Open file for overwrite */
if ((fp = fopen (filename, "w")))
{
fwrite (swap->data, swap->width * swap->height * swap->bytes, 1, fp);
fclose (fp);
size_t blocks_written;
blocks_written = fwrite (swap->data, swap->width * swap->height * swap->bytes, 1, fp);
/* Check whether all bytes were written and fclose() was able to flush its buffers */
if ((0 != fclose (fp)) || (1 != blocks_written))
{
(void) unlink (filename);
perror ("Write error on temp buf");
g_message ("Cannot write \"%s\"", filename);
g_free (filename);
return;
}
}
else
{
(void) unlink (filename);
perror ("Error in temp buf caching");
g_message ("Cannot write \"%s\"", filename);
g_free (filename);
@ -522,11 +532,11 @@ temp_buf_unswap (buf)
{
if ((fp = fopen (buf->filename, "r")))
{
size_t blocksRead;
blocksRead = fread (buf->data, buf->width * buf->height * buf->bytes, 1, fp);
fclose (fp);
if (blocksRead != 1)
perror ("Read error on temp buf");
size_t blocks_read;
blocks_read = fread (buf->data, buf->width * buf->height * buf->bytes, 1, fp);
(void) fclose (fp);
if (blocks_read != 1)
perror ("Read error on temp buf");
else
succ = TRUE;
}

View File

@ -35,13 +35,17 @@ tips_dialog_create ()
guchar * temp;
guchar * src;
guchar * dest;
gchar * gimp_data_dir;
int x;
int y;
if (tips_count == 0)
{
temp = g_malloc (512);
sprintf ((char *)temp, "%s/%s", DATADIR, TIPS_FILE_NAME);
if ((gimp_data_dir = getenv ("GIMP_DATADIR")) != NULL)
sprintf ((char *)temp, "%s/%s", gimp_data_dir, TIPS_FILE_NAME);
else
sprintf ((char *)temp, "%s/%s", DATADIR, TIPS_FILE_NAME);
read_tips_file ((char *)temp);
g_free (temp);
}

View File

@ -372,6 +372,7 @@ install_run (InstallCallback callback)
GdkFont *font;
FILE *pfp;
char buffer[2048];
char *gimp_data_dir;
struct stat stat_buf;
int err;
int executable = TRUE;
@ -415,7 +416,11 @@ install_run (InstallCallback callback)
gtk_text_insert (GTK_TEXT (text), font_strong, NULL, NULL, "User Installation Log\n\n", -1);
/* Generate output */
sprintf (buffer, "%s/user_install", DATADIR);
if ((gimp_data_dir = getenv ("GIMP_DATADIR")) != NULL)
sprintf (buffer, "%s/user_install", gimp_data_dir);
else
sprintf (buffer, "%s/user_install", DATADIR);
if ((err = stat (buffer, &stat_buf)) != 0)
{
gtk_text_insert (GTK_TEXT (text), font, NULL, NULL, buffer, -1);
@ -433,8 +438,13 @@ install_run (InstallCallback callback)
if (executable == TRUE)
{
sprintf (buffer, "%s/user_install %s %s", DATADIR, DATADIR,
gimp_directory ());
if (gimp_data_dir)
sprintf (buffer, "%s/user_install %s %s", gimp_data_dir, gimp_data_dir,
gimp_directory ());
else
sprintf (buffer, "%s/user_install %s %s", DATADIR, DATADIR,
gimp_directory ());
if ((pfp = popen (buffer, "r")) != NULL)
{
while (fgets (buffer, 2048, pfp))

View File

@ -284,6 +284,7 @@ parse_gimprc ()
{
char libfilename[512];
char filename[512];
char *gimp_data_dir;
char *gimp_dir;
parse_info.buffer = g_new (char, 4096);
@ -294,7 +295,11 @@ parse_gimprc ()
gimp_dir = gimp_directory ();
add_gimp_directory_token (gimp_dir);
sprintf (libfilename, "%s/gimprc", DATADIR);
if ((gimp_data_dir = getenv ("GIMP_DATADIR")) != NULL)
sprintf (libfilename, "%s/gimprc", gimp_data_dir);
else
sprintf (libfilename, "%s/gimprc", DATADIR);
app_init_update_status("Resource configuration", libfilename, -1);
parse_gimprc_file (libfilename);

View File

@ -35,13 +35,17 @@ tips_dialog_create ()
guchar * temp;
guchar * src;
guchar * dest;
gchar * gimp_data_dir;
int x;
int y;
if (tips_count == 0)
{
temp = g_malloc (512);
sprintf ((char *)temp, "%s/%s", DATADIR, TIPS_FILE_NAME);
if ((gimp_data_dir = getenv ("GIMP_DATADIR")) != NULL)
sprintf ((char *)temp, "%s/%s", gimp_data_dir, TIPS_FILE_NAME);
else
sprintf ((char *)temp, "%s/%s", DATADIR, TIPS_FILE_NAME);
read_tips_file ((char *)temp);
g_free (temp);
}

View File

@ -372,6 +372,7 @@ install_run (InstallCallback callback)
GdkFont *font;
FILE *pfp;
char buffer[2048];
char *gimp_data_dir;
struct stat stat_buf;
int err;
int executable = TRUE;
@ -415,7 +416,11 @@ install_run (InstallCallback callback)
gtk_text_insert (GTK_TEXT (text), font_strong, NULL, NULL, "User Installation Log\n\n", -1);
/* Generate output */
sprintf (buffer, "%s/user_install", DATADIR);
if ((gimp_data_dir = getenv ("GIMP_DATADIR")) != NULL)
sprintf (buffer, "%s/user_install", gimp_data_dir);
else
sprintf (buffer, "%s/user_install", DATADIR);
if ((err = stat (buffer, &stat_buf)) != 0)
{
gtk_text_insert (GTK_TEXT (text), font, NULL, NULL, buffer, -1);
@ -433,8 +438,13 @@ install_run (InstallCallback callback)
if (executable == TRUE)
{
sprintf (buffer, "%s/user_install %s %s", DATADIR, DATADIR,
gimp_directory ());
if (gimp_data_dir)
sprintf (buffer, "%s/user_install %s %s", gimp_data_dir, gimp_data_dir,
gimp_directory ());
else
sprintf (buffer, "%s/user_install %s %s", DATADIR, DATADIR,
gimp_directory ());
if ((pfp = popen (buffer, "r")) != NULL)
{
while (fgets (buffer, 2048, pfp))

View File

@ -372,6 +372,7 @@ install_run (InstallCallback callback)
GdkFont *font;
FILE *pfp;
char buffer[2048];
char *gimp_data_dir;
struct stat stat_buf;
int err;
int executable = TRUE;
@ -415,7 +416,11 @@ install_run (InstallCallback callback)
gtk_text_insert (GTK_TEXT (text), font_strong, NULL, NULL, "User Installation Log\n\n", -1);
/* Generate output */
sprintf (buffer, "%s/user_install", DATADIR);
if ((gimp_data_dir = getenv ("GIMP_DATADIR")) != NULL)
sprintf (buffer, "%s/user_install", gimp_data_dir);
else
sprintf (buffer, "%s/user_install", DATADIR);
if ((err = stat (buffer, &stat_buf)) != 0)
{
gtk_text_insert (GTK_TEXT (text), font, NULL, NULL, buffer, -1);
@ -433,8 +438,13 @@ install_run (InstallCallback callback)
if (executable == TRUE)
{
sprintf (buffer, "%s/user_install %s %s", DATADIR, DATADIR,
gimp_directory ());
if (gimp_data_dir)
sprintf (buffer, "%s/user_install %s %s", gimp_data_dir, gimp_data_dir,
gimp_directory ());
else
sprintf (buffer, "%s/user_install %s %s", DATADIR, DATADIR,
gimp_directory ());
if ((pfp = popen (buffer, "r")) != NULL)
{
while (fgets (buffer, 2048, pfp))

View File

@ -474,11 +474,21 @@ temp_buf_swap (buf)
/* Open file for overwrite */
if ((fp = fopen (filename, "w")))
{
fwrite (swap->data, swap->width * swap->height * swap->bytes, 1, fp);
fclose (fp);
size_t blocks_written;
blocks_written = fwrite (swap->data, swap->width * swap->height * swap->bytes, 1, fp);
/* Check whether all bytes were written and fclose() was able to flush its buffers */
if ((0 != fclose (fp)) || (1 != blocks_written))
{
(void) unlink (filename);
perror ("Write error on temp buf");
g_message ("Cannot write \"%s\"", filename);
g_free (filename);
return;
}
}
else
{
(void) unlink (filename);
perror ("Error in temp buf caching");
g_message ("Cannot write \"%s\"", filename);
g_free (filename);
@ -522,11 +532,11 @@ temp_buf_unswap (buf)
{
if ((fp = fopen (buf->filename, "r")))
{
size_t blocksRead;
blocksRead = fread (buf->data, buf->width * buf->height * buf->bytes, 1, fp);
fclose (fp);
if (blocksRead != 1)
perror ("Read error on temp buf");
size_t blocks_read;
blocks_read = fread (buf->data, buf->width * buf->height * buf->bytes, 1, fp);
(void) fclose (fp);
if (blocks_read != 1)
perror ("Read error on temp buf");
else
succ = TRUE;
}

View File

@ -35,13 +35,17 @@ tips_dialog_create ()
guchar * temp;
guchar * src;
guchar * dest;
gchar * gimp_data_dir;
int x;
int y;
if (tips_count == 0)
{
temp = g_malloc (512);
sprintf ((char *)temp, "%s/%s", DATADIR, TIPS_FILE_NAME);
if ((gimp_data_dir = getenv ("GIMP_DATADIR")) != NULL)
sprintf ((char *)temp, "%s/%s", gimp_data_dir, TIPS_FILE_NAME);
else
sprintf ((char *)temp, "%s/%s", DATADIR, TIPS_FILE_NAME);
read_tips_file ((char *)temp);
g_free (temp);
}

View File

@ -372,6 +372,7 @@ install_run (InstallCallback callback)
GdkFont *font;
FILE *pfp;
char buffer[2048];
char *gimp_data_dir;
struct stat stat_buf;
int err;
int executable = TRUE;
@ -415,7 +416,11 @@ install_run (InstallCallback callback)
gtk_text_insert (GTK_TEXT (text), font_strong, NULL, NULL, "User Installation Log\n\n", -1);
/* Generate output */
sprintf (buffer, "%s/user_install", DATADIR);
if ((gimp_data_dir = getenv ("GIMP_DATADIR")) != NULL)
sprintf (buffer, "%s/user_install", gimp_data_dir);
else
sprintf (buffer, "%s/user_install", DATADIR);
if ((err = stat (buffer, &stat_buf)) != 0)
{
gtk_text_insert (GTK_TEXT (text), font, NULL, NULL, buffer, -1);
@ -433,8 +438,13 @@ install_run (InstallCallback callback)
if (executable == TRUE)
{
sprintf (buffer, "%s/user_install %s %s", DATADIR, DATADIR,
gimp_directory ());
if (gimp_data_dir)
sprintf (buffer, "%s/user_install %s %s", gimp_data_dir, gimp_data_dir,
gimp_directory ());
else
sprintf (buffer, "%s/user_install %s %s", DATADIR, DATADIR,
gimp_directory ());
if ((pfp = popen (buffer, "r")) != NULL)
{
while (fgets (buffer, 2048, pfp))