From nobody Sun Apr 28 20:25:41 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508980508801561.3870939483613; Wed, 25 Oct 2017 18:15:08 -0700 (PDT) Received: from localhost ([::1]:50503 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7WlC-0000x6-G2 for importer@patchew.org; Wed, 25 Oct 2017 21:15:02 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 =20 +#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 =3D 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 */ --=20 2.10.2