From patchwork Fri Oct 20 17:55:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 828754 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oMhURQ6Z"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yJYQQ48Vvz9t32 for ; Sat, 21 Oct 2017 04:56:46 +1100 (AEDT) Received: from localhost ([::1]:55148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5bXI-00048F-L4 for incoming@patchwork.ozlabs.org; Fri, 20 Oct 2017 13:56:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48547) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5bWi-00045c-Q9 for qemu-devel@nongnu.org; Fri, 20 Oct 2017 13:56:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e5bWh-0000Tu-Tp for qemu-devel@nongnu.org; Fri, 20 Oct 2017 13:56:08 -0400 Received: from mail-io0-x244.google.com ([2607:f8b0:4001:c06::244]:56173) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e5bWd-0000Sa-A2; Fri, 20 Oct 2017 13:56:03 -0400 Received: by mail-io0-x244.google.com with SMTP id p186so14036164ioe.12; Fri, 20 Oct 2017 10:56:03 -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=bCmXvg3SoX/9rCAUQF9MVTZK5zvIK0CpGVO6oIwTYbk=; b=oMhURQ6ZuuuZw0z2Tj8tsFHuruWQS4QthFAKFMyf/OTynmEfM7kzPv3M+vMWhV/QXj efmEyKsFgnfEaBhGh27jn+ox1kplj7KQivW6vGdgPQaSDBYEVK0clpUlxUyYdPPnlQ9C /ly5E9nJTgbZoLIhkmmEhhLaOq0yLR4ZQRCw+jd7lQlogPvj25/UJWKdGIWsCt/QtMH9 EedmrOq+y1AuOSLBVUJ92KkwKf0dBOMPoOFFVecPhwifG/giomd9kULS2wmA7O4rApX2 F0y6feT+W4WnPwZ4waVLM6cwecTx98pVyVTrENKU6K5QIUOPSk8WLPezDYPfM22aBfeT KoWQ== 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=bCmXvg3SoX/9rCAUQF9MVTZK5zvIK0CpGVO6oIwTYbk=; b=Ux2Vaqm/iXDQ7cZS2yTlTyvgCV4kiTWHzEtlE4cKlQjXd22WlH05ICTl53a9I6axft znY/t7b9l9BnUC6fj/KwdakIBMp4dl7ykksapEmL8U/VKfyA51gVEn/w0vZQMwEDtMWR 7uRyM13uVgK4BYQS7Dte5u9fwFWB1JxcB1+ode1gc28IvBgzq4qvWjFfGXHVH5gRXU6d bCTCafKCFtmY95DhEaPh/6mILQ9wsOaRZztC6shovA4qBDxhIsUAKMegPlUw0XSD4T8G dSPhnNiBiNp6qSI0NaG+2lG8dv5vImP2I5qdCZmI1TiG6nAZFyWRiOgWcCmhXHDUI53k yk6w== X-Gm-Message-State: AMCzsaWeEHCT9hnYiAZD+kYI6ns0R944i9x6lIHJ2u1j/4jJUNpZ+5p1 TMho5KFDosUVW0hJyLSXhg4= X-Google-Smtp-Source: ABhQp+Q8u8z6ue27ixQC4/LBWw8W6uVIrs9Y4j0C1PUleLka/yoIVkEOAkS5CjHYky8xVv4Q0hOAww== X-Received: by 10.107.154.138 with SMTP id c132mr6793341ioe.95.1508522162441; Fri, 20 Oct 2017 10:56:02 -0700 (PDT) Received: from localhost.localdomain (d14-69-20-184.try.wideopenwest.com. [69.14.184.20]) by smtp.gmail.com with ESMTPSA id n135sm731774itg.29.2017.10.20.10.56.01 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 20 Oct 2017 10:56:01 -0700 (PDT) From: John Arbuckle To: david@gibson.dropbear.id.au, devicetree-compiler@vger.kernel.org, qemu-ppc@nongnu.org, qemu-devel@nongnu.org Date: Fri, 20 Oct 2017 13:55:48 -0400 Message-Id: <20171020175548.2566-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 v2] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- v2 changes: - Simplified the code to make it static inline'ed - Changed the type of count to size_t libfdt/libfdt_env.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/libfdt/libfdt_env.h b/libfdt/libfdt_env.h index 952056c..2569339 100644 --- a/libfdt/libfdt_env.h +++ b/libfdt/libfdt_env.h @@ -109,4 +109,33 @@ 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) +{ + size_t count; + for (count = 0; count < max_count; count++) { + if (string[count] == '\0') { + break; + } + } + return count; +} + +#endif /* (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7) */ + +#endif /* __APPLE__ */ + #endif /* _LIBFDT_ENV_H */