{"id":884,"url":"https://patchwork.libcamera.org/api/patches/884/?format=json","web_url":"https://patchwork.libcamera.org/patch/884/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20190403041058.20921-4-kieran.bingham@ideasonboard.com>","date":"2019-04-03T04:10:57","name":"[libcamera-devel,v3,3/4] libcamera: utils: Use internal basename implementation.","commit_ref":"0e1a80952524e672ce8ce5eb900740dda2ae9044","pull_url":null,"state":"accepted","archived":false,"hash":"f28855bb3023903666271b2027dc0d0d2e305f8d","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/884/mbox/","series":[{"id":234,"url":"https://patchwork.libcamera.org/api/series/234/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=234","date":"2019-04-03T04:10:54","name":"Cleanup and non-GNU C library support","version":3,"mbox":"https://patchwork.libcamera.org/series/234/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/884/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/884/checks/","tags":{},"headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4C956610C5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Apr 2019 06:11:15 +0200 (CEST)","from Q.imgcgcw.net (unknown [147.50.13.10])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7C74B2F9;\n\tWed,  3 Apr 2019 06:11:13 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1554264675;\n\tbh=u/r0C3H0odrcIWVJYaG8nR+ghaq4nqbGcIRVHSg4psU=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=J0UGi7LOwLsKXuyJ0nXuTSqyibvOKjclbiu02K+S6wtiz5mCehV7GTn899bebK+78\n\tAaQ3W44nUMcaVrq9ONjamM5M8j02x4Wn0sD41MJ0iJNo+95/rq38bqPt5Bj1/+iRpC\n\t78ULeUMUpvXtSuEFxyRtG7g8uv7gjdTgL1RyI+fk=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Date":"Wed,  3 Apr 2019 11:10:57 +0700","Message-Id":"<20190403041058.20921-4-kieran.bingham@ideasonboard.com>","X-Mailer":"git-send-email 2.19.1","In-Reply-To":"<20190403041058.20921-1-kieran.bingham@ideasonboard.com>","References":"<20190403041058.20921-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 3/4] libcamera: utils: Use internal\n\tbasename implementation.","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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>","X-List-Received-Date":"Wed, 03 Apr 2019 04:11:15 -0000"},"content":"Differing implementations of basename() exist, some of which may modify\nthe content of the string passed as an argument.\n\nThe implementation of basename() is trivial, thus to support different\nC librariese, provide our own version which accepts and returns a const\nchar *.\n\nUpdate the call sites to use the new implementation.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/libcamera/include/utils.h |  2 ++\n src/libcamera/log.cpp         |  2 +-\n src/libcamera/meson.build     |  1 +\n src/libcamera/utils.cpp       | 51 +++++++++++++++++++++++++++++++++++\n 4 files changed, 55 insertions(+), 1 deletion(-)\n create mode 100644 src/libcamera/utils.cpp","diff":"diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h\nindex 73fa2e69b029..1b2a62c0fda7 100644\n--- a/src/libcamera/include/utils.h\n+++ b/src/libcamera/include/utils.h\n@@ -15,6 +15,8 @@ namespace libcamera {\n \n namespace utils {\n \n+const char *basename(const char *path);\n+\n /* C++11 doesn't provide std::make_unique */\n template<typename T, typename... Args>\n std::unique_ptr<T> make_unique(Args&&... args)\ndiff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\nindex 26ebf410a7a9..eb444c31857d 100644\n--- a/src/libcamera/log.cpp\n+++ b/src/libcamera/log.cpp\n@@ -438,7 +438,7 @@ void LogMessage::init(const char *fileName, unsigned int line)\n \n \tmsgStream_ << \" \" << log_severity_name(severity_);\n \tmsgStream_ << \" \" << category_.name();\n-\tmsgStream_ << \" \" << basename(fileName) << \":\" << line << \" \";\n+\tmsgStream_ << \" \" << utils::basename(fileName) << \":\" << line << \" \";\n }\n \n LogMessage::~LogMessage()\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 8384cd0af451..863cb60d4b90 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -16,6 +16,7 @@ libcamera_sources = files([\n     'signal.cpp',\n     'stream.cpp',\n     'timer.cpp',\n+    'utils.cpp',\n     'v4l2_device.cpp',\n     'v4l2_subdevice.cpp',\n ])\ndiff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\nnew file mode 100644\nindex 000000000000..fae28cee556a\n--- /dev/null\n+++ b/src/libcamera/utils.cpp\n@@ -0,0 +1,51 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * utils.cpp - Miscellaneous utility functions\n+ */\n+\n+#include <string.h>\n+#include <sys/auxv.h>\n+\n+#include \"utils.h\"\n+\n+/**\n+ * \\file utils.h\n+ * \\brief Miscellaneous utility functions\n+ */\n+\n+namespace libcamera {\n+\n+namespace utils {\n+\n+/**\n+ * \\def ARRAY_SIZE(array)\n+ * \\brief Determine the number of elements in the static array.\n+ */\n+\n+/**\n+ * \\brief Strip the directory prefix from the path\n+ * \\param[in] path The path to process\n+ *\n+ * basename is implemented differently across different C libraries. This\n+ * implementation matches the one provided by the GNU libc, and does not\n+ * modify its input parameter.\n+ *\n+ * \\return A pointer within the given path without any leading directory\n+ * components.\n+ */\n+const char *basename(const char *path)\n+{\n+       const char *base = strrchr(path, '/');\n+       return base ? base + 1 : path;\n+}\n+\n+/**\n+ * \\fn libcamera::utils::make_unique(Args &&... args)\n+ * \\brief Constructs an object of type T and wraps it in a std::unique_ptr.\n+ */\n+\n+} /* namespace utils */\n+\n+} /* namespace libcamera */\n","prefixes":["libcamera-devel","v3","3/4"]}