From: Tim-Philipp Müller Date: Wed, 29 Jun 2005 16:11:12 +0000 (+0000) Subject: gst/elements/gstfilesink.c: Simplify code so that we don't have to handle short write... X-Git-Tag: RELEASE-0_9_2~326 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=38565eafdbc89e6e6b638e035e97ab92bc64d8eb;p=platform%2Fupstream%2Fgstreamer.git gst/elements/gstfilesink.c: Simplify code so that we don't have to handle short writes and return GST_FLOW_ERROR if a... Original commit message from CVS: * gst/elements/gstfilesink.c: (gst_filesink_render): Simplify code so that we don't have to handle short writes and return GST_FLOW_ERROR if an error occured. --- diff --git a/ChangeLog b/ChangeLog index 8431495..b73242c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-06-29 Tim-Philipp Müller + + * gst/elements/gstfilesink.c: (gst_filesink_render): + Simplify code so that we don't have to handle short + writes and return GST_FLOW_ERROR if an error occured. + 2005-06-29 Ronald S. Bultje * docs/gst/gstreamer-docs.sgml: diff --git a/gst/elements/gstfilesink.c b/gst/elements/gstfilesink.c index cc44e97..d6323eb 100644 --- a/gst/elements/gstfilesink.c +++ b/gst/elements/gstfilesink.c @@ -359,8 +359,7 @@ static GstFlowReturn gst_filesink_render (GstBaseSink * sink, GstBuffer * buffer) { GstFileSink *filesink; - guint bytes_written = 0, back_pending = 0; - guint size; + guint size, back_pending = 0; size = GST_BUFFER_SIZE (buffer); @@ -369,21 +368,14 @@ gst_filesink_render (GstBaseSink * sink, GstBuffer * buffer) if (ftell (filesink->file) < filesink->data_written) back_pending = filesink->data_written - ftell (filesink->file); - while (bytes_written < size) { - size_t wrote = fwrite (GST_BUFFER_DATA (buffer) + bytes_written, 1, - size - bytes_written, filesink->file); - - if (wrote <= 0) { - GST_ELEMENT_ERROR (filesink, RESOURCE, WRITE, - (_("Error while writing to file \"%s\"."), filesink->filename), - ("Only %d of %d bytes written: %s", - bytes_written, size, strerror (errno))); - break; - } - bytes_written += wrote; + if (fwrite (GST_BUFFER_DATA (buffer), size, 1, filesink->file) != 1) { + GST_ELEMENT_ERROR (filesink, RESOURCE, WRITE, + (_("Error while writing to file \"%s\"."), filesink->filename), + ("%s", g_strerror (errno))); + return GST_FLOW_ERROR; } - filesink->data_written += bytes_written - back_pending; + filesink->data_written += size - back_pending; return GST_FLOW_OK; } diff --git a/plugins/elements/gstfilesink.c b/plugins/elements/gstfilesink.c index cc44e97..d6323eb 100644 --- a/plugins/elements/gstfilesink.c +++ b/plugins/elements/gstfilesink.c @@ -359,8 +359,7 @@ static GstFlowReturn gst_filesink_render (GstBaseSink * sink, GstBuffer * buffer) { GstFileSink *filesink; - guint bytes_written = 0, back_pending = 0; - guint size; + guint size, back_pending = 0; size = GST_BUFFER_SIZE (buffer); @@ -369,21 +368,14 @@ gst_filesink_render (GstBaseSink * sink, GstBuffer * buffer) if (ftell (filesink->file) < filesink->data_written) back_pending = filesink->data_written - ftell (filesink->file); - while (bytes_written < size) { - size_t wrote = fwrite (GST_BUFFER_DATA (buffer) + bytes_written, 1, - size - bytes_written, filesink->file); - - if (wrote <= 0) { - GST_ELEMENT_ERROR (filesink, RESOURCE, WRITE, - (_("Error while writing to file \"%s\"."), filesink->filename), - ("Only %d of %d bytes written: %s", - bytes_written, size, strerror (errno))); - break; - } - bytes_written += wrote; + if (fwrite (GST_BUFFER_DATA (buffer), size, 1, filesink->file) != 1) { + GST_ELEMENT_ERROR (filesink, RESOURCE, WRITE, + (_("Error while writing to file \"%s\"."), filesink->filename), + ("%s", g_strerror (errno))); + return GST_FLOW_ERROR; } - filesink->data_written += bytes_written - back_pending; + filesink->data_written += size - back_pending; return GST_FLOW_OK; }