qemu-ppc
[Top][All Lists]
Advanced

[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: Programmingkid
Subject: Re: [Qemu-ppc] [Qemu-devel] [libfdt][PATCH v3] implement strnlen for systems that need it
Date: Tue, 24 Oct 2017 09:37:38 -0400

> On Oct 24, 2017, at 8:09 AM, Stefan Hajnoczi <address@hidden> wrote:
> 
> On Mon, Oct 23, 2017 at 11:13:13PM -0400, Programmingkid wrote:
>> 
>>> On Oct 23, 2017, at 12:09 PM, Stefan Hajnoczi <address@hidden> wrote:
>>> 
>>> 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
>> 
>> Sounds logical.
>> 
>>> 
>>>> +/* 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).
>> 
>> If MAC_OS_X_VERSION_MAX_ALLOWED is equal to 1070 then this code would not be 
>> executed. This branch would only be taken if MAC_OS_X_VERSION_MAX_ALLOWED is 
>> less than 1070. So there would not be a 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
>> 
>> I think you are saying I should remove the "#ifdef __APPLE__" code and just 
>> check to see if MAC_OS_X_VERSION_10_7 is defined. That might work on Mac OS 
>> 10.6 and 10.5, but it would probably cause problems with non-Mac-OS 
>> platforms. 
> 
> No, the ifndef is still "indented" and it would be like this:
> 
> #ifdef __APPLE_
> ...
> # ifndef MAC_OS_X_VERSION_10_7

I see. This is a more compact way of doing things. 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]