From: chrubis@suse.cz
To: Alexey Kodanev <alexey.kodanev@oracle.com>
Cc: vasily.isaenko@oracle.com, ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH] Create a function tst_resm_hexd to print a buffer in hex
Date: Tue, 21 May 2013 14:49:05 +0200 [thread overview]
Message-ID: <20130521124905.GC28186@rei> (raw)
In-Reply-To: <1369066734-17683-1-git-send-email-alexey.kodanev@oracle.com>
A little more detailed description of the new function here please.
> Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
> ---
> @@ -40,6 +40,7 @@
> * FUNCTION NAME :
> * tst_res() - Print result message (include file contents)
> * tst_resm() - Print result message
> + * tst_resm_hexd() - Print result message (add buffer contents in hex)
> * tst_brk() - Print result message (include file contents)
> * and break remaining test cases
> * tst_brkm() - Print result message and break remaining test
> @@ -62,6 +63,12 @@
> * int ttype;
> * char *tmesg;
> *
> + * void tst_resm_hexd(ttype, buf, size, tmesg [,arg]...)
> + * int ttype;
> + * const void *buf;
> + * size_t size;
> + * char *tmesg;
This part of the comment is IMHO useless as nobody will read the C code
when looking for documentation and evenmore this does not add more
information than the prototype in header. (I made a note to clean these
up later).
> * void tst_brk(ttype, fname, cleanup, tmesg, [,argv]...)
> * int ttype;
> * char *fname;
> @@ -675,6 +682,47 @@ void tst_resm(int ttype, char *arg_fmt, ...)
> }
>
> /*
> + * tst_resm_hexd() - Interface to tst_res(), with no filename.
> + * Also, dump specified buffer in hex.
> + */
> +void tst_resm_hexd(int ttype, const void *buf, size_t size, char *arg_fmt, ...)
> +{
> + char tmesg[USERMESG];
> +
> +#if DEBUG
> + printf("IN tst_resm_hexd\n");
> + fflush(stdout);
> +#endif
> +
> + EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG);
> +
> + static const char msg_end[] = " ...";
> + static const size_t symb_num = 3; /* space + xx */
> + size_t end_num = strlen(msg_end);
I think that todays compilers can avoid the call to strlen() on static
string but I would either hardcode the size of the string below or even
better use sizeof() which returns strlen() + 1 in this case.
> + size_t offset = strlen(tmesg);
> + int size_changed = 0;
> +
> + if ((offset + symb_num * size + 1) >= USERMESG) {
> + size = (USERMESG - offset) / symb_num - end_num - 1;
(USERMESG - offset - sizeof(msg_end)) / symb_num ?
> + size_changed = 1;
> + }
> +
> + char *pmesg = tmesg + offset;
> +
> + size_t i;
> + for (i = 0; i < size; ++i) {
> + sprintf(pmesg, " %02x", ((unsigned char *)buf)[i]);
> + pmesg += symb_num;
> + }
> +
> + if (size_changed)
> + strcat(pmesg, msg_end);
Shouldn't strcpy() suffice here?
> + tst_res(ttype, NULL, "%s", tmesg);
> +}
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next prev parent reply other threads:[~2013-05-21 12:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-20 16:18 [LTP] [PATCH] Create a function tst_resm_hexd to print a buffer in hex Alexey Kodanev
2013-05-21 12:49 ` chrubis [this message]
[not found] ` <519B8E4E.1010105@oracle.com>
2013-05-21 15:46 ` chrubis
[not found] ` <519B9B8D.6050004@oracle.com>
2013-05-21 16:32 ` chrubis
-- strict thread matches above, loose matches on Subject: below --
2013-05-21 14:38 [LTP] [PATCH] Create a function tst_resm_hexd() " Alexey Kodanev
2013-05-21 14:42 Alexey Kodanev
2013-05-22 10:10 Alexey Kodanev
2013-05-22 12:56 ` chrubis
2013-05-23 7:03 Alexey Kodanev
2013-05-23 13:08 ` chrubis
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=20130521124905.GC28186@rei \
--to=chrubis@suse.cz \
--cc=alexey.kodanev@oracle.com \
--cc=ltp-list@lists.sourceforge.net \
--cc=vasily.isaenko@oracle.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox