From nobody Sun Apr 28 19:16:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) 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=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) 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 1508727104221454.4214217664352; Sun, 22 Oct 2017 19:51:44 -0700 (PDT) Received: from localhost ([::1]:36598 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6Sq1-0007i5-R1 for importer@patchew.org; Sun, 22 Oct 2017 22:51:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35872) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6Sp0-0007Lj-Pf for qemu-devel@nongnu.org; Sun, 22 Oct 2017 22:50:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6Sov-0005Ji-TM for qemu-devel@nongnu.org; Sun, 22 Oct 2017 22:50:34 -0400 Received: from mail-it0-x241.google.com ([2607:f8b0:4001:c0b::241]:43745) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e6Sov-0005JS-Ox; Sun, 22 Oct 2017 22:50:29 -0400 Received: by mail-it0-x241.google.com with SMTP id k70so4692094itk.0; Sun, 22 Oct 2017 19:50:29 -0700 (PDT) Received: from localhost.localdomain (d14-69-20-184.try.wideopenwest.com. [69.14.184.20]) by smtp.gmail.com with ESMTPSA id 128sm2756827iow.59.2017.10.22.19.50.27 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 22 Oct 2017 19:50:28 -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=IXkjcSnDYlxWyCyrCsFnwtgwjAzgBd/BgGonjD7CRAw=; b=rtYmXca/28CymD77a1vhALkSXL0v4HmQMGKJxtz3dJIgIo5prPGH0jbmcoLukvUZfh Dc2AYTJCkAMGPvbU0d+IvVXGYhzMqYQg49TvBrO5DkuQ+HBvQ/cuMXAQ+5rBKqHWtLQ6 108nTQoa5lJNbxnpFDxm5OXHnO7FgmJVSnKi//IX5o16tkWK1fW+R9Z96936tS20jFOZ cIYj6wNpBUuCEUMk6qnJP9oOmI8avuu/oE3OK7H+q1nIlQp0OPBd4w68DE3s8Lq+vlOI IsR0F1MBu6NrpFGGZDGMoMDiNWSzjv6JGD7QPeP2w0ZDwv1mLcxKwWwzaiHZoQNC9bhU 6SnQ== 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=IXkjcSnDYlxWyCyrCsFnwtgwjAzgBd/BgGonjD7CRAw=; b=bLCWOeQqN2j/hpWt6Wc6ucE2XH9WMvWrOiLWqCDwUf221utEJ0rs6jY2XmSl9RGEhl y9MCpItnfCQ48hzqLofjkVA8RJwF7+V8yvNTVkhoOCF6GIEwW+Ac39y538xBA+NgvfOI ryBSi6TfW2saV383aObIHVZaPDUijSU0CbR58ScDqRb29X1Sxmi7r+dbySn7WFSJcr2I ivklfwIatsDhKcHc/6AghjeiiWUb0vL5pqJi1d6dAecggJy4izQf0cZudK/xs/M7KDFJ H7NfeNeE5lOEq75gBbAlNKD3p9S1ha4dN5uhOo2eHmpZU5pj6dcvVbwczeFYzHR6e8s3 VnJQ== X-Gm-Message-State: AMCzsaWqDmNltBeF8Uysf6XPHhhHUPOb2vq9WFW2D1U2HknX/Pjhxwl5 l+O4XncbOyTYvCs+htdHvBY= X-Google-Smtp-Source: ABhQp+SCOGHlKJkhhlZYSX3yiGFFlXSbjCEqehRJJS+myxwqGe/OvfKJQuRYry8iVd9bGpEuWA/DSg== X-Received: by 10.36.179.79 with SMTP id z15mr7270301iti.131.1508727028952; Sun, 22 Oct 2017 19:50:28 -0700 (PDT) From: John Arbuckle To: david@gibson.dropbear.id.au, richard.henderson@linaro.org, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, peter.maydell@linaro.org, devicetree-compiler@vger.kernel.org, ian@freebsd.org Date: Sun, 22 Oct 2017 22:50:16 -0400 Message-Id: <20171023025016.3088-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:c0b::241 Subject: [Qemu-devel] [libfdt][PATCH v3] 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_0 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 --- 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 =20 +#ifdef __APPLE__ +#include + +#define MAC_OS_X_VERSION_10_7 1070 + +/* strnlen() is not available on Mac OS < 10.7 */ +# if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7) + +/* + * strnlen: returns the length of a string or max_count - which ever is sm= allest + * 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 strnlen(const char *string, size_t max_count) +{ + const char *p =3D memchr(string, 0, max_count); + return p ? p - string : max_count; +} + +#endif /* (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7) */ + +#endif /* __APPLE__ */ + #endif /* _LIBFDT_ENV_H */ --=20 2.10.2