[{"id":1239,"web_url":"https://patchwork.libcamera.org/comment/1239/","msgid":"<20190403054002.GA4813@pendragon.ideasonboard.com>","date":"2019-04-03T05:40:02","subject":"Re: [libcamera-devel] [PATCH v3 3/4] libcamera: utils: Use internal\n\tbasename implementation.","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Wed, Apr 03, 2019 at 11:10:57AM +0700, Kieran Bingham wrote:\n> Differing implementations of basename() exist, some of which may modify\n> the content of the string passed as an argument.\n> \n> The implementation of basename() is trivial, thus to support different\n> C librariese, provide our own version which accepts and returns a const\n> char *.\n> \n> Update the call sites to use the new implementation.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\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\n> \n> diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h\n> index 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)\n> diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\n> index 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()\n> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\n> index 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>  ])\n> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\n> new file mode 100644\n> index 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 */","headers":{"Return-Path":"<laurent.pinchart@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 518C6610B3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Apr 2019 07:40:13 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C75092F9;\n\tWed,  3 Apr 2019 07:40:12 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1554270012;\n\tbh=Qzhlm6yKqpkQlqoN+v+Z+izXUBB1cINGQxWK68B3WOM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ZE4R19/xc1Ci2Fph7C+LVAQLn2apz+m/KMEm2PTe15i50wCFfIPA6APfM/0GCikgq\n\tBe1NZ//kclPpuIhxREDZQqA7m4AMB221OfKodFx1B7ow38TdMSoj9dOQbM74mld/rq\n\tH198MSi/6PENU+XBbSfxDXIkwedEJwi6bIG64yv4=","Date":"Wed, 3 Apr 2019 08:40:02 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Message-ID":"<20190403054002.GA4813@pendragon.ideasonboard.com>","References":"<20190403041058.20921-1-kieran.bingham@ideasonboard.com>\n\t<20190403041058.20921-4-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190403041058.20921-4-kieran.bingham@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [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 05:40:13 -0000"}}]