Simplify calls to g_output_stream_write_all()
It returns TRUE only if all bytes were written, so there is no need to get and check the bytes_written return value.
This commit is contained in:
parent
d249ec348b
commit
14978bfe5d
14 changed files with 29 additions and 86 deletions
|
|
@ -41,7 +41,6 @@ gimp_brush_generated_save (GimpData *data,
|
|||
const gchar *name = gimp_object_get_name (data);
|
||||
GString *string;
|
||||
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
|
||||
gsize bytes_written;
|
||||
gboolean have_shape = FALSE;
|
||||
|
||||
g_return_val_if_fail (name != NULL && *name != '\0', FALSE);
|
||||
|
|
@ -107,8 +106,7 @@ gimp_brush_generated_save (GimpData *data,
|
|||
brush->angle));
|
||||
|
||||
if (! g_output_stream_write_all (output, string->str, string->len,
|
||||
&bytes_written, NULL, error) ||
|
||||
bytes_written != string->len)
|
||||
NULL, NULL, error))
|
||||
{
|
||||
g_string_free (string, TRUE);
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ gimp_gradient_save (GimpData *data,
|
|||
GString *string;
|
||||
GimpGradientSegment *seg;
|
||||
gint num_segments;
|
||||
gsize bytes_written;
|
||||
|
||||
/* File format is:
|
||||
*
|
||||
|
|
@ -108,8 +107,7 @@ gimp_gradient_save (GimpData *data,
|
|||
}
|
||||
|
||||
if (! g_output_stream_write_all (output, string->str, string->len,
|
||||
&bytes_written, NULL, error) ||
|
||||
bytes_written != string->len)
|
||||
NULL, NULL, error))
|
||||
{
|
||||
g_string_free (string, TRUE);
|
||||
|
||||
|
|
@ -131,7 +129,6 @@ gimp_gradient_save_pov (GimpGradient *gradient,
|
|||
GimpGradientSegment *seg;
|
||||
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
|
||||
gchar color_buf[4][G_ASCII_DTOSTR_BUF_SIZE];
|
||||
gsize bytes_written;
|
||||
GError *my_error = NULL;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_GRADIENT (gradient), FALSE);
|
||||
|
|
@ -214,8 +211,7 @@ gimp_gradient_save_pov (GimpGradient *gradient,
|
|||
g_string_append_printf (string, "} /* color_map */\n");
|
||||
|
||||
if (! g_output_stream_write_all (output, string->str, string->len,
|
||||
&bytes_written, NULL, &my_error) ||
|
||||
bytes_written != string->len)
|
||||
NULL, NULL, &my_error))
|
||||
{
|
||||
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_WRITE,
|
||||
_("Writing POV file '%s' failed: %s"),
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ gimp_palette_save (GimpData *data,
|
|||
GimpPalette *palette = GIMP_PALETTE (data);
|
||||
GString *string;
|
||||
GList *list;
|
||||
gsize bytes_written;
|
||||
|
||||
string = g_string_new ("GIMP Palette\n");
|
||||
|
||||
|
|
@ -65,8 +64,7 @@ gimp_palette_save (GimpData *data,
|
|||
}
|
||||
|
||||
if (! g_output_stream_write_all (output, string->str, string->len,
|
||||
&bytes_written, NULL, error) ||
|
||||
bytes_written != string->len)
|
||||
NULL, NULL, error))
|
||||
{
|
||||
g_string_free (string, TRUE);
|
||||
|
||||
|
|
|
|||
|
|
@ -603,7 +603,6 @@ gimp_curves_config_save_cruft (GimpCurvesConfig *config,
|
|||
GError **error)
|
||||
{
|
||||
GString *string;
|
||||
gsize bytes_written;
|
||||
gint i;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_CURVES_CONFIG (config), FALSE);
|
||||
|
|
@ -667,8 +666,7 @@ gimp_curves_config_save_cruft (GimpCurvesConfig *config,
|
|||
}
|
||||
|
||||
if (! g_output_stream_write_all (output, string->str, string->len,
|
||||
&bytes_written, NULL, error) ||
|
||||
bytes_written != string->len)
|
||||
NULL, NULL, error))
|
||||
{
|
||||
g_prefix_error (error, _("Writing curves file failed: "));
|
||||
g_string_free (string, TRUE);
|
||||
|
|
|
|||
|
|
@ -844,7 +844,6 @@ gimp_levels_config_save_cruft (GimpLevelsConfig *config,
|
|||
GError **error)
|
||||
{
|
||||
GString *string;
|
||||
gsize bytes_written;
|
||||
gint i;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_LEVELS_CONFIG (config), FALSE);
|
||||
|
|
@ -868,8 +867,7 @@ gimp_levels_config_save_cruft (GimpLevelsConfig *config,
|
|||
}
|
||||
|
||||
if (! g_output_stream_write_all (output, string->str, string->len,
|
||||
&bytes_written, NULL, error) ||
|
||||
bytes_written != string->len)
|
||||
NULL, NULL, error))
|
||||
{
|
||||
g_prefix_error (error, _("Writing levels file failed: "));
|
||||
g_string_free (string, TRUE);
|
||||
|
|
|
|||
|
|
@ -422,8 +422,7 @@ gimp_pdb_print_entry (gpointer key,
|
|||
GEnumClass *proc_class;
|
||||
GString *buf;
|
||||
GString *string;
|
||||
gsize bytes_written;
|
||||
gint num = 0;
|
||||
gint num = 0;
|
||||
|
||||
if (pdb_dump->error)
|
||||
return;
|
||||
|
|
@ -596,7 +595,7 @@ gimp_pdb_print_entry (gpointer key,
|
|||
}
|
||||
|
||||
g_output_stream_write_all (output, string->str, string->len,
|
||||
&bytes_written, NULL, &pdb_dump->error);
|
||||
NULL, NULL, &pdb_dump->error);
|
||||
|
||||
g_string_free (string, TRUE);
|
||||
g_string_free (buf, TRUE);
|
||||
|
|
|
|||
|
|
@ -65,7 +65,6 @@ gimp_vectors_export_file (const GimpImage *image,
|
|||
{
|
||||
GOutputStream *output;
|
||||
GString *string;
|
||||
gsize bytes_written;
|
||||
GError *my_error = NULL;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
|
||||
|
|
@ -89,8 +88,7 @@ gimp_vectors_export_file (const GimpImage *image,
|
|||
string = gimp_vectors_export (image, vectors);
|
||||
|
||||
if (! g_output_stream_write_all (output, string->str, string->len,
|
||||
&bytes_written, NULL, &my_error) ||
|
||||
bytes_written != string->len)
|
||||
NULL, NULL, &my_error))
|
||||
{
|
||||
g_set_error (error, my_error->domain, my_error->code,
|
||||
_("Writing SVG file '%s' failed: %s"),
|
||||
|
|
|
|||
|
|
@ -1508,12 +1508,10 @@ gimp_text_buffer_save (GimpTextBuffer *buffer,
|
|||
|
||||
if (text_contents)
|
||||
{
|
||||
gint text_length = strlen (text_contents);
|
||||
gsize bytes_written;
|
||||
gint text_length = strlen (text_contents);
|
||||
|
||||
if (! g_output_stream_write_all (output, text_contents, text_length,
|
||||
&bytes_written, NULL, &my_error) ||
|
||||
bytes_written != text_length)
|
||||
NULL, NULL, &my_error))
|
||||
{
|
||||
g_set_error (error, my_error->domain, my_error->code,
|
||||
_("Writing palette file '%s' failed: %s"),
|
||||
|
|
|
|||
|
|
@ -74,7 +74,6 @@ static gboolean gimp_config_writer_close_output (GimpConfigWriter *writer,
|
|||
static inline void
|
||||
gimp_config_writer_flush (GimpConfigWriter *writer)
|
||||
{
|
||||
gsize bytes_written;
|
||||
GError *error = NULL;
|
||||
|
||||
if (! writer->output)
|
||||
|
|
@ -83,8 +82,7 @@ gimp_config_writer_flush (GimpConfigWriter *writer)
|
|||
if (! g_output_stream_write_all (writer->output,
|
||||
writer->buffer->str,
|
||||
writer->buffer->len,
|
||||
&bytes_written,
|
||||
NULL, &error))
|
||||
NULL, NULL, &error))
|
||||
{
|
||||
g_set_error (&writer->error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
|
||||
_("Error writing to '%s': %s"),
|
||||
|
|
@ -658,12 +656,10 @@ gimp_config_writer_linefeed (GimpConfigWriter *writer)
|
|||
|
||||
if (writer->output && writer->buffer->len == 0 && !writer->comment)
|
||||
{
|
||||
gsize bytes_written;
|
||||
GError *error = NULL;
|
||||
|
||||
if (! g_output_stream_write_all (writer->output, "\n", 1,
|
||||
&bytes_written,
|
||||
NULL, &error))
|
||||
NULL, NULL, &error))
|
||||
{
|
||||
g_set_error (&writer->error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
|
||||
_("Error writing to '%s': %s"),
|
||||
|
|
|
|||
|
|
@ -647,7 +647,6 @@ save_image (GFile *file,
|
|||
gint width;
|
||||
gint height;
|
||||
GimpRGB gray, white;
|
||||
gsize bytes_written;
|
||||
|
||||
gimp_rgba_set_uchar (&white, 255, 255, 255, 255);
|
||||
|
||||
|
|
@ -693,8 +692,7 @@ save_image (GFile *file,
|
|||
bh.spacing = g_htonl (info.spacing);
|
||||
|
||||
if (! g_output_stream_write_all (output, &bh, sizeof (BrushHeader),
|
||||
&bytes_written, NULL, error) ||
|
||||
bytes_written != sizeof (BrushHeader))
|
||||
NULL, NULL, error))
|
||||
{
|
||||
g_object_unref (output);
|
||||
return FALSE;
|
||||
|
|
@ -703,8 +701,7 @@ save_image (GFile *file,
|
|||
if (! g_output_stream_write_all (output,
|
||||
info.description,
|
||||
strlen (info.description) + 1,
|
||||
&bytes_written, NULL, error) ||
|
||||
bytes_written != strlen (info.description) + 1)
|
||||
NULL, NULL, error))
|
||||
{
|
||||
g_object_unref (output);
|
||||
return FALSE;
|
||||
|
|
@ -744,8 +741,7 @@ save_image (GFile *file,
|
|||
}
|
||||
|
||||
if (! g_output_stream_write_all (output, brush_buf, width * file_bpp,
|
||||
&bytes_written, NULL, error) ||
|
||||
bytes_written != width * file_bpp)
|
||||
NULL, NULL, error))
|
||||
{
|
||||
g_free (brush_buf);
|
||||
g_object_unref (output);
|
||||
|
|
|
|||
|
|
@ -1185,7 +1185,6 @@ gih_save_one_brush (GOutputStream *output,
|
|||
GimpImageType drawable_type;
|
||||
gint bpp;
|
||||
guint y;
|
||||
gsize bytes_written;
|
||||
|
||||
buffer = gimp_drawable_get_buffer (drawable_ID);
|
||||
|
||||
|
|
@ -1222,15 +1221,13 @@ gih_save_one_brush (GOutputStream *output,
|
|||
bh.spacing = g_htonl (info.spacing);
|
||||
|
||||
if (! g_output_stream_write_all (output, &bh, sizeof (bh),
|
||||
&bytes_written, NULL, error) ||
|
||||
bytes_written != sizeof (bh))
|
||||
NULL, NULL, error))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (! g_output_stream_write_all (output, name, strlen (name) + 1,
|
||||
&bytes_written, NULL, error) ||
|
||||
bytes_written != strlen (name) + 1)
|
||||
NULL, NULL, error))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
|
@ -1254,8 +1251,7 @@ gih_save_one_brush (GOutputStream *output,
|
|||
}
|
||||
|
||||
if (! g_output_stream_write_all (output, data, rect->width * bpp,
|
||||
&bytes_written, NULL, error) ||
|
||||
bytes_written != rect->width * bpp)
|
||||
NULL, NULL, error))
|
||||
{
|
||||
g_free (data);
|
||||
return FALSE;
|
||||
|
|
@ -1286,7 +1282,6 @@ gih_save_image (GFile *file,
|
|||
gint imagew, imageh;
|
||||
gint offsetx, offsety;
|
||||
gint k;
|
||||
gsize bytes_written;
|
||||
|
||||
if (gihparams.ncells < 1)
|
||||
return FALSE;
|
||||
|
|
@ -1307,8 +1302,7 @@ gih_save_image (GFile *file,
|
|||
info.description, gihparams.ncells, parstring);
|
||||
|
||||
if (! g_output_stream_write_all (output, header, strlen (header),
|
||||
&bytes_written, NULL, error) ||
|
||||
bytes_written != strlen (header))
|
||||
NULL, NULL, error))
|
||||
{
|
||||
g_free (parstring);
|
||||
g_free (header);
|
||||
|
|
|
|||
|
|
@ -486,7 +486,6 @@ save_image (GFile *file,
|
|||
gint height;
|
||||
gint line_size;
|
||||
gint line;
|
||||
gsize bytes_written;
|
||||
|
||||
switch (gimp_drawable_type (drawable_ID))
|
||||
{
|
||||
|
|
@ -535,8 +534,7 @@ save_image (GFile *file,
|
|||
ph.magic_number = g_htonl (GPATTERN_MAGIC);
|
||||
|
||||
if (! g_output_stream_write_all (output, &ph, sizeof (PatternHeader),
|
||||
&bytes_written, NULL, error) ||
|
||||
bytes_written != sizeof (PatternHeader))
|
||||
NULL, NULL, error))
|
||||
{
|
||||
g_object_unref (output);
|
||||
return FALSE;
|
||||
|
|
@ -544,8 +542,7 @@ save_image (GFile *file,
|
|||
|
||||
if (! g_output_stream_write_all (output,
|
||||
description, strlen (description) + 1,
|
||||
&bytes_written, NULL, error) ||
|
||||
bytes_written != strlen (description) + 1)
|
||||
NULL, NULL, error))
|
||||
{
|
||||
g_object_unref (output);
|
||||
return FALSE;
|
||||
|
|
@ -563,8 +560,7 @@ save_image (GFile *file,
|
|||
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
||||
|
||||
if (! g_output_stream_write_all (output, buf, line_size,
|
||||
&bytes_written, NULL, error) ||
|
||||
bytes_written != line_size)
|
||||
NULL, NULL, error))
|
||||
{
|
||||
g_object_unref (buffer);
|
||||
g_object_unref (output);
|
||||
|
|
|
|||
|
|
@ -318,14 +318,11 @@ put_short (GOutputStream *output,
|
|||
GError **error)
|
||||
{
|
||||
guchar buf[2];
|
||||
gsize bytes_written;
|
||||
|
||||
buf[0] = (value >> 8) & 0xFF;
|
||||
buf[1] = value & 0xFF;
|
||||
|
||||
return (g_output_stream_write_all (output, buf, 2,
|
||||
&bytes_written, NULL, error) &&
|
||||
bytes_written == 2);
|
||||
return g_output_stream_write_all (output, buf, 2, NULL, NULL, error);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -598,7 +595,6 @@ save_image (GFile *file,
|
|||
/* Write a row of the image */
|
||||
|
||||
guchar record[4];
|
||||
gsize bytes_written;
|
||||
|
||||
record[0] = 1;
|
||||
record[3] = src[0];
|
||||
|
|
@ -615,9 +611,7 @@ save_image (GFile *file,
|
|||
/* Write current RLE record and start a new one */
|
||||
|
||||
if (! g_output_stream_write_all (output, record, 4,
|
||||
&bytes_written, NULL,
|
||||
error) ||
|
||||
bytes_written != 4)
|
||||
NULL, NULL, error))
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
|
@ -638,9 +632,7 @@ save_image (GFile *file,
|
|||
/* Write last record in row */
|
||||
|
||||
if (! g_output_stream_write_all (output, record, 4,
|
||||
&bytes_written, NULL,
|
||||
error) ||
|
||||
bytes_written != 4)
|
||||
NULL, NULL, error))
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
|
@ -672,7 +664,6 @@ save_image (GFile *file,
|
|||
/* Write a row of the image */
|
||||
|
||||
guchar record[2];
|
||||
gsize bytes_written;
|
||||
|
||||
record[0] = 1;
|
||||
record[1] = src[0];
|
||||
|
|
@ -684,9 +675,7 @@ save_image (GFile *file,
|
|||
/* Write current RLE record and start a new one */
|
||||
|
||||
if (! g_output_stream_write_all (output, record, 2,
|
||||
&bytes_written, NULL,
|
||||
error) ||
|
||||
bytes_written != 2)
|
||||
NULL, NULL, error))
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
|
@ -705,9 +694,7 @@ save_image (GFile *file,
|
|||
/* Write last record in row */
|
||||
|
||||
if (! g_output_stream_write_all (output, record, 2,
|
||||
&bytes_written, NULL,
|
||||
error) ||
|
||||
bytes_written != 2)
|
||||
NULL, NULL, error))
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -870,16 +870,7 @@ output_write (GOutputStream *output,
|
|||
gsize count,
|
||||
GError **error)
|
||||
{
|
||||
gsize bytes_written;
|
||||
|
||||
if (! g_output_stream_write_all (output, buffer, count,
|
||||
&bytes_written, NULL, error) ||
|
||||
bytes_written != count)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return g_output_stream_write_all (output, buffer, count, NULL, NULL, error);
|
||||
}
|
||||
|
||||
/* Writes out mono raw rows */
|
||||
|
|
|
|||
Loading…
Reference in a new issue