From: Deborah Brouwer <deborah.brouwer@collabora.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: linux-media@vger.kernel.org
Subject: Re: [PATCH 2/5] v4l2-tracer: remove trailing comma from JSON trace
Date: Wed, 22 Feb 2023 12:43:04 -0800 [thread overview]
Message-ID: <Y/Z+WMoaR1d2d/vX@xps> (raw)
In-Reply-To: <a00558a5-2168-8f86-5db8-a8b3f3928a37@xs4all.nl>
On Wed, Feb 22, 2023 at 08:26:33PM +0100, Hans Verkuil wrote:
> On 09/02/2023 07:06, Deborah Brouwer wrote:
> > Put the trace file into valid JSON format by removing the trailing comma
> > from the trace file array.
> >
> > Signed-off-by: Deborah Brouwer <deborah.brouwer@collabora.com>
> > ---
> > utils/v4l2-tracer/v4l2-tracer.cpp | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/utils/v4l2-tracer/v4l2-tracer.cpp b/utils/v4l2-tracer/v4l2-tracer.cpp
> > index ae6f68e4..7adbe04e 100644
> > --- a/utils/v4l2-tracer/v4l2-tracer.cpp
> > +++ b/utils/v4l2-tracer/v4l2-tracer.cpp
> > @@ -346,7 +346,7 @@ int tracer(int argc, char *argv[], bool retrace)
> >
> > /* Close the json-array and the trace file. */
> > trace_file = fopen(trace_filename.c_str(), "a");
> > - fseek(trace_file, 0L, SEEK_END);
> > + ftruncate(fileno(trace_file), lseek(fileno(trace_file), 0, SEEK_END) - 2);
> > fputs("\n]\n", trace_file);
>
> ftruncate seems overkill to me. Wouldn't it be enough to just do
>
> fseek(trace_file, -2, SEEK_END);
>
> since the fputs afterwards will overwrite those last two characters anyway?
>
> (I think it is -2 for SEEK_END, I'm not 100% certain though, it could be 2)
It took me a while to remember why I didn't use this simpler method,
but it's because the trace file is opened in append mode "a" in
write_json_object_to_json_file() and so fputs() stubbornly ignores the
file position indicator set by fseek.
>
> Regards,
>
> Hans
>
> > fclose(trace_file);
> >
>
next prev parent reply other threads:[~2023-02-22 20:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-09 6:06 [PATCH 0/5] v4l2-tracer: misc fixes Deborah Brouwer
2023-02-09 6:06 ` [PATCH 1/5] v4l2-tracer: add signal handling Deborah Brouwer
2023-02-09 6:06 ` [PATCH 2/5] v4l2-tracer: remove trailing comma from JSON trace Deborah Brouwer
2023-02-22 19:26 ` Hans Verkuil
2023-02-22 20:43 ` Deborah Brouwer [this message]
2023-02-09 6:06 ` [PATCH 3/5] v4l2-tracer: refactor autogeneration script Deborah Brouwer
2023-02-09 6:06 ` [PATCH 4/5] v4l2-tracer: add exact matching for 'type' and 'field' Deborah Brouwer
2023-02-09 6:06 ` [PATCH 5/5] v4l2-tracer: add INPUT and OUTPUT ioctls Deborah Brouwer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y/Z+WMoaR1d2d/vX@xps \
--to=deborah.brouwer@collabora.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-media@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.