From: David Gibson <david@gibson.dropbear.id.au>
To: John Arbuckle <programmingkidx@gmail.com>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] fdt_ro.c: implement strnlen
Date: Thu, 19 Oct 2017 12:31:26 +1100 [thread overview]
Message-ID: <20171019013126.GR2776@umbus.fritz.box> (raw)
In-Reply-To: <20171018223116.6035-1-programmingkidx@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2209 bytes --]
On Wed, Oct 18, 2017 at 06:31:16PM -0400, John Arbuckle wrote:
> Implement the strnlen() function if it isn't implemented.
>
> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
Nice idea, but this won't work.
> ---
> libfdt/fdt_ro.c | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
> index 3d00d2e..a7986fb 100644
> --- a/libfdt/fdt_ro.c
> +++ b/libfdt/fdt_ro.c
> @@ -55,6 +55,30 @@
>
> #include "libfdt_internal.h"
>
> +/* if the current environment does not define strnlen */
> +#ifndef strnlen
This will only trigger if strnlen is defined as a macro. The C
library (or other environment) *might* do that, but there's no
guarantee, whether or not it defines strnlen as a function. With
extra complications if the compiler has a strnlen builtin like gcc.
> +
> +/* This eliminates the missing prototype warning */
> +int strnlen(const char *string, int max_count);
> +
> +/*
> + * strnlen: return the length of a string or max_count
> + * which ever is shortest
> + */
> +
> +int strnlen(const char *string, int max_count)
Also strnlen is supposed to take and return size_t, not int.
> +{
> + int count;
> + for(count = 0; count < max_count; count++) {
> + if (string[count] == '\0') {
> + break;
> + }
> + }
> + return count;
> +}
> +
> +#endif /* strnlen */
> +
> static int _fdt_nodename_eq(const void *fdt, int offset,
> const char *s, int len)
> {
In any case, this sort of compatibility munging is the job of
libfdt_env.h. It's purpose is to provide all the external things that
libfdt needs - there's not that many of them and strnlen() is one.
The included libfdt_env.h is intended for POSIXy userspace
environments, which should already include strnlen() in string.h.
If your environment does not provide strnlen(), you probably need your
own version of libfdt_env.h, which will need to define it.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2017-10-19 2:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-18 22:31 [Qemu-devel] [PATCH] fdt_ro.c: implement strnlen John Arbuckle
2017-10-19 1:31 ` David Gibson [this message]
2017-10-19 2:39 ` Programmingkid
2017-10-19 4:11 ` David Gibson
2017-10-19 9:37 ` Peter Maydell
2017-10-19 14:54 ` Programmingkid
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=20171019013126.GR2776@umbus.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=programmingkidx@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).