mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-27 11:32:51 +00:00
trace: don't put code with side effects into g_return_if_fail()
This commit is contained in:
parent
d353ddf38e
commit
76559d4160
1 changed files with 16 additions and 3 deletions
|
@ -55,6 +55,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if defined (_MSC_VER) && _MSC_VER >= 1400
|
||||
# include <io.h>
|
||||
|
@ -168,14 +169,23 @@ gst_trace_destroy (GstTrace * trace)
|
|||
void
|
||||
gst_trace_flush (GstTrace * trace)
|
||||
{
|
||||
int res, buf_len;
|
||||
|
||||
if (!trace) {
|
||||
trace = _gst_trace_default;
|
||||
if (!trace)
|
||||
return;
|
||||
}
|
||||
|
||||
g_return_if_fail (write (trace->fd, trace->buf,
|
||||
trace->bufoffset * sizeof (GstTraceEntry)) != -1);
|
||||
buf_len = trace->bufoffset * sizeof (GstTraceEntry);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -206,7 +216,10 @@ gst_trace_text_flush (GstTrace * trace)
|
|||
g_snprintf (str, STRSIZE, "%20" G_GINT64_FORMAT " %10d %10d %s\n",
|
||||
trace->buf[i].timestamp,
|
||||
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;
|
||||
#undef STRSIZE
|
||||
|
|
Loading…
Reference in a new issue