From patchwork Thu Oct 26 01:13:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 10027375 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B91D56032C for ; Thu, 26 Oct 2017 01:14:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A688128C32 for ; Thu, 26 Oct 2017 01:14:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B35528C8A; Thu, 26 Oct 2017 01:14:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1CF6C28C32 for ; Thu, 26 Oct 2017 01:14:48 +0000 (UTC) Received: from localhost ([::1]:50500 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7Wkx-0000bi-Ln for patchwork-qemu-devel@patchwork.kernel.org; Wed, 25 Oct 2017 21:14:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47546) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7WkG-0000aE-IJ for qemu-devel@nongnu.org; Wed, 25 Oct 2017 21:14:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e7WkD-00055Q-DM for qemu-devel@nongnu.org; Wed, 25 Oct 2017 21:14:04 -0400 Received: from mail-io0-x244.google.com ([2607:f8b0:4001:c06::244]:56131) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e7WkD-00054x-8e; Wed, 25 Oct 2017 21:14:01 -0400 Received: by mail-io0-x244.google.com with SMTP id p186so2967542ioe.12; Wed, 25 Oct 2017 18:14:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=DPR0cWQHfJLT42dGNgvzEWdcHjUcTthQfQcpTVpOKNc=; b=oSdbaTpallPy/C6L3e3Id06wzjuTU9DjrT4HS+TlrvCTr5UbPXEAVwvj0/Gvj/6dAE gT0aguSD1Lo+NoP1b4fueEdr1sUPAHcfl8qiGBzD7bEuEyzB9QPNsT5Y9PzoJHITk+8Z SStJF5Bv6uf9YdknffNtc2ic92LDeoaj2oxiRJQGJAtadENiRbX8VtVXOFfY8LBueGCH 5DDYLm2/2dR00e/RV+6B0yVp8WKZtnaKGWgDmdCuf5E0BdrLpSbrvkRBD/orkaTQ1Ulu Ecly+LwTBM4ROu4UaGnIi6Sh+RUU4+eUsFZyNr6COV32kn+Y+pgks7BF4tooCpNzjgSL gqQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=DPR0cWQHfJLT42dGNgvzEWdcHjUcTthQfQcpTVpOKNc=; b=KH3nAusRrEPgMe/ZzD8NDbl2xv9fv7XNwtuKlyOyLfoQDVgPqLA1xnPtEnVgZRjFGq Td4CkCPMV8L18qrv5bGGI02mIV+lFvWKNzqht8v5uetuM9GHaZPF8mlHMtWLQrS2w0h8 WtD7IhW1leQDbYux5DVsNgaGiJXwau/Rt1XzT83cNqBxuRabOoB5b0EOP57uQQWEV+f8 Nc05d7hPkX5I8+hGsnPE4s7JRGPn4DbhBgye1xtzAKQX0z+JG3KC8GUdSOkzEYTP3Eqh CCk4gWIH0/QBRVq1lnXDoTUTt0Dn/oW7q4A7w/qxa5rlFgWentNSxxw3s6LKzogbm1oI 7a2g== X-Gm-Message-State: AMCzsaW6hiw7EXTkWSwDuMX0BQdfmcQAAdXkeE6BXPvfGN6FHO1wY1Dz mRDRuHXyjG1OQa9gKmknK6o= X-Google-Smtp-Source: ABhQp+Rr76tP2eAEDNMbxI15c3kHgFaUIpceVVNO10dGfAwmK1qDBXcv4sXmkOOGGu96xRc76KZJcw== X-Received: by 10.107.111.14 with SMTP id k14mr25524380ioc.282.1508980440496; Wed, 25 Oct 2017 18:14:00 -0700 (PDT) Received: from localhost.localdomain (d14-69-20-184.try.wideopenwest.com. [69.14.184.20]) by smtp.gmail.com with ESMTPSA id a90sm1805793ioj.74.2017.10.25.18.13.58 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 25 Oct 2017 18:13:59 -0700 (PDT) From: John Arbuckle To: stefanha@gmail.com, peter.maydell@linaro.org, david@gibson.dropbear.id.au, richard.henderson@linaro.org, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, devicetree-compiler@vger.kernel.org, ian@freebsd.org Date: Wed, 25 Oct 2017 21:13:46 -0400 Message-Id: <20171026011346.5758-1-programmingkidx@gmail.com> X-Mailer: git-send-email 2.13.5 (Apple Git-94) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c06::244 Subject: [Qemu-devel] [libfdt][PATCH v4] implement strnlen for systems that need it X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Arbuckle Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- v4 changes: - Added check for definition of MAC_OS_X_VERSION_10_7 - Renamed strnlen to fdt_strnlen - Added macro that defines strnlen as fdt_strnlen 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 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/libfdt/libfdt_env.h b/libfdt/libfdt_env.h index 952056c..41fac04 100644 --- a/libfdt/libfdt_env.h +++ b/libfdt/libfdt_env.h @@ -109,4 +109,31 @@ static inline fdt64_t cpu_to_fdt64(uint64_t x) #undef CPU_TO_FDT16 #undef EXTRACT_BYTE +#ifdef __APPLE__ +#include + +/* strnlen() is not available on Mac OS < 10.7 */ +# if !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED < \ + MAC_OS_X_VERSION_10_7) + +#define strnlen fdt_strnlen + +/* + * fdt_strnlen: returns the length of a string or max_count - which ever is + * smallest. + * Input 1 string: the string whose size is to be determined + * Input 2 max_count: the maximum value returned by this function + * Output: length of the string or max_count (the smallest of the two) + */ +static inline size_t fdt_strnlen(const char *string, size_t max_count) +{ + const char *p = memchr(string, 0, max_count); + return p ? p - string : max_count; +} + +#endif /* !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED < + MAC_OS_X_VERSION_10_7) */ + +#endif /* __APPLE__ */ + #endif /* _LIBFDT_ENV_H */