From patchwork Mon Oct 23 02:50:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 10021931 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 E9396603D7 for ; Mon, 23 Oct 2017 02:51:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDB24286CB for ; Mon, 23 Oct 2017 02:51:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C03D7286F3; Mon, 23 Oct 2017 02:51:23 +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 4ABA9286CB for ; Mon, 23 Oct 2017 02:51:22 +0000 (UTC) Received: from localhost ([::1]:36596 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6Spk-0007Lp-S7 for patchwork-qemu-devel@patchwork.kernel.org; Sun, 22 Oct 2017 22:51:20 -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) 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) 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) 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+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 --- 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 + +#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 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 strnlen(const char *string, size_t max_count) +{ + const char *p = 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 */