From patchwork Fri Oct 20 01:50:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 10018573 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 6613860234 for ; Fri, 20 Oct 2017 01:51:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 587CE28E24 for ; Fri, 20 Oct 2017 01:51:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D56928E81; Fri, 20 Oct 2017 01:51:05 +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 CD7E128E24 for ; Fri, 20 Oct 2017 01:51:04 +0000 (UTC) Received: from localhost ([::1]:51861 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5MSl-0007Yt-R0 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 19 Oct 2017 21:51:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43882) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5MS7-0007XS-F9 for qemu-devel@nongnu.org; Thu, 19 Oct 2017 21:50:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e5MS6-00009c-7n for qemu-devel@nongnu.org; Thu, 19 Oct 2017 21:50:23 -0400 Received: from mail-io0-x244.google.com ([2607:f8b0:4001:c06::244]:54845) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e5MS1-000058-91; Thu, 19 Oct 2017 21:50:17 -0400 Received: by mail-io0-x244.google.com with SMTP id e89so11799307ioi.11; Thu, 19 Oct 2017 18:50:15 -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=sd/v7tgaC229eEoXO/V6E+7BqVEAGmaaaNdelYlpRts=; b=WQELHv0mPsjxQxmHTMeKA3LHSgqw7fG865uNi6+GkheM9pPnNveY3a/mw1lbDLT+2/ sK1ZsBh6B7v0PBF507ZDkowmYs57mqGHvGT0dd9K4YMs60oWnVHpsi2ysPyuHHt/82Dp SYeBpNk1uG581O0l64HBk/HyEMhghkI9EHfeFbYxWkKML6WgNre0ssSpVKOf+iGtQK5v J402zclRbmlTilFAbnj5gZJuErUOx+N1dqM09gXaRpRHflGShdbf8UYgaToazZUY0PQ8 1GPC4KUHu0INjh5iaCF1sQTWLGpdkIrHM+RlBQUp21kwKkLlYvoVlOvJVcwFANgKMEJw jLAw== 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=sd/v7tgaC229eEoXO/V6E+7BqVEAGmaaaNdelYlpRts=; b=gjNKjJ5u4OwNB/osT9pID3SkvWj33EK10iEWYEzudx3E4I/5yw67gl7UgTB+w2RFFb 4N2J1Bd4FHKelTbZ9GPD6MaVny1e5bbZ3C4QwIx1NhdgcM2Baya3Aj7jWvksoWQXJdHK CnhYYAhqzPbz44iKTkmKQNgjrv4PRZ00q/ilURXB0IxsBlXlN47EiiXIQQVNsHfs1x2x YdbjTCxVZSg6WNVtNR1kF0EczRBGzDJyoOlpB51k51agb7F5MMRglqHafk7n/9ep/+oB Uz9HCjqxuR/xVzv5ojffG1RpMcVX8V/nymrRbxxbfoI6m3JQIj2JXhjSrxOHwl3x1Nqd a42g== X-Gm-Message-State: AMCzsaU54G8tbSElF9GkAjQvQUuhS6xo5tCiNhkHFpV8AMYcmQAdWy1e G2aGhvri4qHCZ29UbI71Zy3rJA== X-Google-Smtp-Source: ABhQp+QZkk9C6lc062oXLgFOrRe/cJ/agvtHK/gUUzO9CWdp4oJUC3KJaJntrjom3UNARKk6hKZKvA== X-Received: by 10.107.53.42 with SMTP id c42mr4615132ioa.254.1508464215077; Thu, 19 Oct 2017 18:50:15 -0700 (PDT) Received: from localhost.localdomain (d14-69-20-184.try.wideopenwest.com. [69.14.184.20]) by smtp.gmail.com with ESMTPSA id e88sm58506itd.34.2017.10.19.18.50.13 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 19 Oct 2017 18:50:14 -0700 (PDT) From: John Arbuckle To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, david@gibson.dropbear.id.au Date: Thu, 19 Oct 2017 21:50:05 -0400 Message-Id: <20171020015005.2311-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] [PATCH] 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 Signed-off-by: John Arbuckle --- Makefile.dtc | 3 ++- libfdt/Makefile.libfdt | 2 +- libfdt/libfdt_env.h | 12 ++++++++++++ libfdt/strnlen.h | 14 ++++++++++++++ strnlen.c | 25 +++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 libfdt/strnlen.h create mode 100644 strnlen.c diff --git a/Makefile.dtc b/Makefile.dtc index bece49b..14eaa4e 100644 --- a/Makefile.dtc +++ b/Makefile.dtc @@ -12,7 +12,8 @@ DTC_SRCS = \ livetree.c \ srcpos.c \ treesource.c \ - util.c + util.c \ + strnlen.c DTC_GEN_SRCS = dtc-lexer.lex.c dtc-parser.tab.c DTC_OBJS = $(DTC_SRCS:%.c=%.o) $(DTC_GEN_SRCS:%.c=%.o) diff --git a/libfdt/Makefile.libfdt b/libfdt/Makefile.libfdt index 098b3f3..b20a85b 100644 --- a/libfdt/Makefile.libfdt +++ b/libfdt/Makefile.libfdt @@ -7,5 +7,5 @@ LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1 LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h LIBFDT_VERSION = version.lds LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \ - fdt_addresses.c fdt_overlay.c + fdt_addresses.c fdt_overlay.c strnlen.c LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o) diff --git a/libfdt/libfdt_env.h b/libfdt/libfdt_env.h index 952056c..a25a615 100644 --- a/libfdt/libfdt_env.h +++ b/libfdt/libfdt_env.h @@ -109,4 +109,16 @@ 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) +#include "strnlen.h" +#endif /* (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7) */ + +#endif /* __APPLE__ */ + #endif /* _LIBFDT_ENV_H */ diff --git a/libfdt/strnlen.h b/libfdt/strnlen.h new file mode 100644 index 0000000..62a45c0 --- /dev/null +++ b/libfdt/strnlen.h @@ -0,0 +1,14 @@ +/* + * File: strnlen.h + * Date: 10-19-2017 + * Description: Implements functions that may be missing on the host system + */ + +#ifndef STRNLEN +#define STRNLEN + +#include + +size_t strnlen(const char *string, size_t max_count); + +#endif /* STRNLEN */ diff --git a/strnlen.c b/strnlen.c new file mode 100644 index 0000000..3559c6f --- /dev/null +++ b/strnlen.c @@ -0,0 +1,25 @@ +/* + * File: strnlen.c + * Date: 10-19-2017 + * Description: Implement the strnlen() function for platforms that need it + */ + +#include +#include "strnlen.h" + +/* + * 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) + */ +size_t strnlen(const char *string, size_t max_count) +{ + int count; + for(count = 0; count < max_count; count++) { + if (string[count] == '\0') { + break; + } + } + return count; +}