From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751784AbdGZRWU (ORCPT ); Wed, 26 Jul 2017 13:22:20 -0400 Received: from terminus.zytor.com ([65.50.211.136]:57393 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751502AbdGZRWS (ORCPT ); Wed, 26 Jul 2017 13:22:18 -0400 Date: Wed, 26 Jul 2017 10:19:02 -0700 From: tip-bot for Arnaldo Carvalho de Melo Message-ID: Cc: tglx@linutronix.de, adrian.hunter@intel.com, keescook@chromium.org, wangnan0@huawei.com, jolsa@kernel.org, mingo@kernel.org, hpa@zytor.com, dsahern@gmail.com, acme@redhat.com, namhyung@kernel.org, linux-kernel@vger.kernel.org Reply-To: hpa@zytor.com, namhyung@kernel.org, dsahern@gmail.com, acme@redhat.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, wangnan0@huawei.com, keescook@chromium.org, adrian.hunter@intel.com, mingo@kernel.org, jolsa@kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] tools lib: Update copy of strtobool from the kernel sources Git-Commit-ID: b99e4850df86dfd9dc2cf3f3494e403ff8b46876 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: b99e4850df86dfd9dc2cf3f3494e403ff8b46876 Gitweb: http://git.kernel.org/tip/b99e4850df86dfd9dc2cf3f3494e403ff8b46876 Author: Arnaldo Carvalho de Melo AuthorDate: Thu, 20 Jul 2017 15:35:33 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 20 Jul 2017 15:47:33 -0300 tools lib: Update copy of strtobool from the kernel sources Getting support for "on", "off" introduced in a81a5a17d44b ("lib: add "on"/"off" support to kstrtobool") and making it check for NULL, introduced in ef951599074b ("lib: move strtobool() to kstrtobool()"). Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Cc: Kees Cook Link: http://lkml.kernel.org/n/tip-mu8ghin4rklacmmubzwv8td7@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/string.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/tools/lib/string.c b/tools/lib/string.c index bd239bc..a4246f1 100644 --- a/tools/lib/string.c +++ b/tools/lib/string.c @@ -39,27 +39,45 @@ void *memdup(const void *src, size_t len) * @s: input string * @res: result * - * This routine returns 0 iff the first character is one of 'Yy1Nn0'. - * Otherwise it will return -EINVAL. Value pointed to by res is - * updated upon finding a match. + * This routine returns 0 iff the first character is one of 'Yy1Nn0', or + * [oO][NnFf] for "on" and "off". Otherwise it will return -EINVAL. Value + * pointed to by res is updated upon finding a match. */ int strtobool(const char *s, bool *res) { + if (!s) + return -EINVAL; + switch (s[0]) { case 'y': case 'Y': case '1': *res = true; - break; + return 0; case 'n': case 'N': case '0': *res = false; - break; + return 0; + case 'o': + case 'O': + switch (s[1]) { + case 'n': + case 'N': + *res = true; + return 0; + case 'f': + case 'F': + *res = false; + return 0; + default: + break; + } default: - return -EINVAL; + break; } - return 0; + + return -EINVAL; } /**