Commit 76559d41 authored by Tim-Philipp Müller's avatar Tim-Philipp Müller
Browse files

trace: don't put code with side effects into g_return_if_fail()

parent d353ddf3
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#include <errno.h>
#if defined (_MSC_VER) && _MSC_VER >= 1400 #if defined (_MSC_VER) && _MSC_VER >= 1400
# include <io.h> # include <io.h>
...@@ -168,14 +169,23 @@ gst_trace_destroy (GstTrace * trace) ...@@ -168,14 +169,23 @@ gst_trace_destroy (GstTrace * trace)
void void
gst_trace_flush (GstTrace * trace) gst_trace_flush (GstTrace * trace)
{ {
int res, buf_len;
if (!trace) { if (!trace) {
trace = _gst_trace_default; trace = _gst_trace_default;
if (!trace) if (!trace)
return; return;
} }
g_return_if_fail (write (trace->fd, trace->buf, buf_len = trace->bufoffset * sizeof (GstTraceEntry);
trace->bufoffset * sizeof (GstTraceEntry)) != -1); res = write (trace->fd, trace->buf, buf_len);
if (res < 0) {
g_warning ("Failed to write trace: %s", g_strerror (errno));
return;
} else if (res < buf_len) {
g_warning ("Failed to write trace: only wrote %d/%d bytes", res, buf_len);
return;
}
trace->bufoffset = 0; trace->bufoffset = 0;
} }
...@@ -206,7 +216,10 @@ gst_trace_text_flush (GstTrace * trace) ...@@ -206,7 +216,10 @@ gst_trace_text_flush (GstTrace * trace)
g_snprintf (str, STRSIZE, "%20" G_GINT64_FORMAT " %10d %10d %s\n", g_snprintf (str, STRSIZE, "%20" G_GINT64_FORMAT " %10d %10d %s\n",
trace->buf[i].timestamp, trace->buf[i].timestamp,
trace->buf[i].sequence, trace->buf[i].data, trace->buf[i].message); trace->buf[i].sequence, trace->buf[i].data, trace->buf[i].message);
g_return_if_fail (write (trace->fd, str, strlen (str)) != -1); if (write (trace->fd, str, strlen (str)) < 0) {
g_warning ("Failed to write trace %d: %s", i, g_strerror (errno));
return;
}
} }
trace->bufoffset = 0; trace->bufoffset = 0;
#undef STRSIZE #undef STRSIZE
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment