> Date: Sat, 8 Apr 2023 13:29:25 +1000
> From: David Gwynne <[email protected]>
>
> turns out OF_getprop is like memcpy, but sometimes you want something
> like strlcpy. this is what OF_getpropstr aims to provide.
>
> i know openfirm.h is used on other archs that don't use fdt as their
> backend, but i figure we can port this wrapper over to them as need
> demands.
>
> ok?
Going to continue to point out the redundant parentheses in your diffs!
So a few small nits.
With those fixed ok kettenis@
> Index: fdt.c
> ===================================================================
> RCS file: /cvs/src/sys/dev/ofw/fdt.c,v
> retrieving revision 1.33
> diff -u -p -r1.33 fdt.c
> --- fdt.c 19 Sep 2022 16:12:19 -0000 1.33
> +++ fdt.c 8 Apr 2023 03:16:39 -0000
> @@ -980,6 +980,18 @@ OF_getprop(int handle, char *prop, void
> }
>
> int
> +OF_getpropstr(int handle, char *prop, char *buf, int buflen)
Can you move this function to after OF_getpropint64array() to keep
them in alphabetical order?
> +{
> + int len;
> +
> + len = OF_getprop(handle, prop, buf, buflen);
> + if (buflen > 0)
> + buf[min(len, buflen - 1)] = '\0';
> +
> + return (len);
return len;
> +}
> +
> +int
> OF_getpropbool(int handle, char *prop)
> {
> void *node = (char *)tree.header + handle;
> Index: openfirm.h
> ===================================================================
> RCS file: /cvs/src/sys/dev/ofw/openfirm.h,v
> retrieving revision 1.18
> diff -u -p -r1.18 openfirm.h
> --- openfirm.h 6 May 2021 19:45:16 -0000 1.18
> +++ openfirm.h 8 Apr 2023 03:16:39 -0000
> @@ -50,6 +50,7 @@ int OF_parent(int phandle);
> int OF_instance_to_package(int ihandle);
> int OF_getproplen(int handle, char *prop);
> int OF_getprop(int handle, char *prop, void *buf, int buflen);
> +int OF_getpropstr(int handle, char *prop, char *buf, int buflen);
Same here, move the proptype after OF_getpropint64array().
> int OF_getpropbool(int handle, char *);
> uint32_t OF_getpropint(int handle, char *, uint32_t);
> int OF_getpropintarray(int, char *, uint32_t *, int);
>
>