[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [libfdt][PATCH v3] implement strnlen for systems that n
From: |
Programmingkid |
Subject: |
Re: [Qemu-devel] [libfdt][PATCH v3] implement strnlen for systems that need it |
Date: |
Wed, 25 Oct 2017 12:18:24 -0400 |
> On Oct 24, 2017, at 8:18 AM, Stefan Hajnoczi <address@hidden> wrote:
>
> On Mon, Oct 23, 2017 at 05:27:26PM +0100, Peter Maydell wrote:
>> On 23 October 2017 at 17:09, Stefan Hajnoczi <address@hidden> wrote:
>>>> +/* 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).
>>
>> In that case you don't want to use the strnlen() declaration
>> from the header, you want the inline somehow, because even if
>> the declaration is present and using it doesn't fail compile
>> the definition won't be around at runtime.
>
> Perhaps one way around this case is to:
>
> # if !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED <
> MAC_OS_X_VERSION_10_7)
> # include <string.h> /* make sure it isn't included again */
> # define strnlen fdt_strnlen
> static inline fdt_strnlen(...) { ... }
>
> This way the symbol strnlen() isn't used and the system headers cannot
> cause problems.
I really like this idea. I will implement it in my next patch. Thanks!