mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-30 12:49:40 +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 <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)
|
||||||
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)
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue