[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-ppc] [Qemu-devel] [libfdt][PATCH v3] implement strnlen for sys
From: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-ppc] [Qemu-devel] [libfdt][PATCH v3] implement strnlen for systems that need it |
Date: |
Mon, 23 Oct 2017 18:09:59 +0200 |
User-agent: |
Mutt/1.9.1 (2017-09-22) |
On Sun, Oct 22, 2017 at 10:50:16PM -0400, John Arbuckle wrote:
> Prior the Mac OS 10.7, the function strnlen() was not available. This patch
> implements strnlen() on Mac OS X versions that are below 10.7.
>
> Signed-off-by: John Arbuckle <address@hidden>
> ---
> v3 changes:
> - Replaced loop with memchr()
>
> v2 changes:
> - Simplified the code to make it static inline'ed
> - Changed the type of count to size_t
>
> libfdt/libfdt_env.h | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/libfdt/libfdt_env.h b/libfdt/libfdt_env.h
> index 952056c..d43b66b 100644
> --- a/libfdt/libfdt_env.h
> +++ b/libfdt/libfdt_env.h
> @@ -109,4 +109,28 @@ static inline fdt64_t cpu_to_fdt64(uint64_t x)
> #undef CPU_TO_FDT16
> #undef EXTRACT_BYTE
>
> +#ifdef __APPLE__
> +#include <AvailabilityMacros.h>
> +
> +#define MAC_OS_X_VERSION_10_7 1070
Apple has already defined MAC_OS_X_VERSION_10_7 here:
https://opensource.apple.com/source/xnu/xnu-1699.24.8/EXTERNAL_HEADERS/AvailabilityMacros.h
To avoid a compiler warning, please use:
#ifndef MAC_OS_X_VERSION_10_7
#define MAC_OS_X_VERSION_10_7 1070
#endif
> +/* strnlen() is not available on Mac OS < 10.7 */
> +# if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7)
Does this cover the case where MAC_OS_X_VERSION_MAX_ALLOWED is set to
<1070 on a 10.7+ build machine? It's possible that the <string.h>
header would define strnlen() and your code redefines the function
(compiler error).
It would be best to check how <string.h>, <Availability.h>, and
<AvailabilityMacros.h> work to make sure that all cases are handled. I
don't have access to a Mac right now, sorry.
Perhaps this approach works better:
# ifndef MAC_OS_X_VERSION_10_7