{"id":17940,"url":"https://patchwork.libcamera.org/api/1.1/patches/17940/?format=json","web_url":"https://patchwork.libcamera.org/patch/17940/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20221202164145.30603-2-jacopo@jmondi.org>","date":"2022-12-02T16:41:45","name":"[libcamera-devel,2/2] libcamera: utils: Provide strchrnul() wrapper","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"c0dcc836f689bb9b39408d31b0563bd13f942b0f","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17940/mbox/","series":[{"id":3656,"url":"https://patchwork.libcamera.org/api/1.1/series/3656/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3656","date":"2022-12-02T16:41:44","name":"[libcamera-devel,1/2] libcamera: utils: Wrap usage of lockf()","version":1,"mbox":"https://patchwork.libcamera.org/series/3656/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17940/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17940/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A92D6C3284\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  2 Dec 2022 16:41:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BEE6A63342;\n\tFri,  2 Dec 2022 17:41:54 +0100 (CET)","from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net\n\t[217.70.183.194])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C8B9360483\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  2 Dec 2022 17:41:52 +0100 (CET)","(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id 63F8D4000B;\n\tFri,  2 Dec 2022 16:41:52 +0000 (UTC)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1669999314;\n\tbh=CpvkOAi3RnVI942NlfvRwJgcBoRlsmxDztZ20i7M/W8=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=rhOMpQZpNER/8zU4NlqO+5b7hiQCa+AFE7mL/eLjLE4SyNO18eUqWtQ9zWLlwV73t\n\tCdxg14FSTVghhAAdGJ7I4J5rFU0Lkclz0Te5ejcueeUasxnJAcvnIpEFWcSeGwxWmX\n\twpfxgCOivwIlElaeSQSdumpCwwyHsl3o+wqZmGoYjjuZehzihCqtIEcuFPcKBG5EWX\n\tcqmCDJofevyERRAR6d5UCtuvzO34i0UK3wCp35vk3nj5zjQSRHX/PtJcG4p7T0p6cV\n\tehBKtublAgp6/bo+HY5qbhgF10xbKVbudx97WzqD2XxelK5AXQj9rfmcIbz3TwlcXj\n\tlEA8UdX3FUR+Q==","To":"libcamera-devel@lists.libcamera.org","Date":"Fri,  2 Dec 2022 17:41:45 +0100","Message-Id":"<20221202164145.30603-2-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.38.1","In-Reply-To":"<20221202164145.30603-1-jacopo@jmondi.org>","References":"<20221202164145.30603-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 2/2] libcamera: utils: Provide strchrnul()\n\twrapper","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo@jmondi.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The strchrnul function is a GNU-specific extension to string.h and it's\nnot availalable on all C libraries (in example, Android's Bionic).\n\nProvide an implementation of the function based around the generally\navailable strchr() function and use it in the Logger class.\n\nOpen code the same wrapper in the application's option parser, where we\ncannot use the internal utils namespace.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/base/utils.h |  1 +\n src/apps/common/options.cpp    |  5 ++++-\n src/libcamera/base/log.cpp     |  2 +-\n src/libcamera/base/utils.cpp   | 19 +++++++++++++++++++\n 4 files changed, 25 insertions(+), 2 deletions(-)","diff":"diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h\nindex eb7bcdf4c173..b7064ec6253b 100644\n--- a/include/libcamera/base/utils.h\n+++ b/include/libcamera/base/utils.h\n@@ -36,6 +36,7 @@ namespace libcamera {\n namespace utils {\n \n const char *basename(const char *path);\n+const char *strchrnul(const char *s, int c);\n \n char *secure_getenv(const char *name);\n std::string dirname(const std::string &path);\ndiff --git a/src/apps/common/options.cpp b/src/apps/common/options.cpp\nindex 4f7e869144c8..1bbbec7fa25c 100644\n--- a/src/apps/common/options.cpp\n+++ b/src/apps/common/options.cpp\n@@ -363,7 +363,10 @@ KeyValueParser::Options KeyValueParser::parse(const char *arguments)\n \tOptions options;\n \n \tfor (const char *pair = arguments; *arguments != '\\0'; pair = arguments) {\n-\t\tconst char *comma = strchrnul(arguments, ',');\n+\t\tconst char *comma = strchr(arguments, ',');\n+\t\tif (!comma)\n+\t\t\tcomma = &arguments[strlen(arguments)];\n+\n \t\tsize_t len = comma - pair;\n \n \t\t/* Skip over the comma. */\ndiff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp\nindex 55fbd7b03438..cc30681fd67f 100644\n--- a/src/libcamera/base/log.cpp\n+++ b/src/libcamera/base/log.cpp\n@@ -629,7 +629,7 @@ void Logger::parseLogLevels()\n \t\treturn;\n \n \tfor (const char *pair = debug; *debug != '\\0'; pair = debug) {\n-\t\tconst char *comma = strchrnul(debug, ',');\n+\t\tconst char *comma = utils::strchrnul(debug, ',');\n \t\tsize_t len = comma - pair;\n \n \t\t/* Skip over the comma. */\ndiff --git a/src/libcamera/base/utils.cpp b/src/libcamera/base/utils.cpp\nindex 6a307940448e..f829a8106b76 100644\n--- a/src/libcamera/base/utils.cpp\n+++ b/src/libcamera/base/utils.cpp\n@@ -39,6 +39,25 @@ const char *basename(const char *path)\n \treturn base ? base + 1 : path;\n }\n \n+/**\n+ * \\brief Implement strchnul wrapper\n+ * \\param[in] s The string to seach on\n+ * \\param[in] c The character to search\n+ *\n+ * The strchrnul function is a GNU-specific extension to string.h and it's not\n+ * available on all C libraries (in example, Android's Bionic). This\n+ * implementation realizes strchrnul() on strchr() which is instead more\n+ * generally available.\n+ *\n+ * \\return A pointer to the first occurrence of \\a c in \\a s, or a pointer to\n+ * the null byte at the end of \\a s if \\a c is not found\n+ */\n+const char *strchrnul(const char *s, int c)\n+{\n+\tconst char *p = strchr(s, c);\n+\treturn p ? : s + strlen(s);\n+}\n+\n /**\n  * \\brief Get an environment variable\n  * \\param[in] name The name of the variable to return\n","prefixes":["libcamera-devel","2/2"]}