From patchwork Thu Feb 20 16:56:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 2860 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 02537625B1 for ; Thu, 20 Feb 2020 17:57:08 +0100 (CET) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 76925E7C; Thu, 20 Feb 2020 17:57:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1582217827; bh=7KuIpS0hSgzefw/xKnhDvgRgggJ1uIYE/5Q7Ei2GHqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XKzs1Xg2azfQHel+irIedj5OBhFUFk7m6IJfiP5elAaIyPYLjcZBplChndVuYIdCg 3igb+eagF1HEOlI3fbAqh9lv2LbW3laG0L3GtC4WYU3znb0oGNQdv+mzu/ALq96rq1 3EvSFnFuVJ6IzyXGHfiwMoTuh0DsSgfag6t+GNVk= From: Kieran Bingham To: libcamera devel Date: Thu, 20 Feb 2020 16:56:59 +0000 Message-Id: <20200220165704.23600-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200220165704.23600-1-kieran.bingham@ideasonboard.com> References: <20200220165704.23600-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/6] libcamera: utils: Add an internal dirname helper X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Feb 2020 16:57:08 -0000 Provide a wrapped dirname call which returns a std::string. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/include/utils.h | 1 + src/libcamera/utils.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h index 080ea6614de0..940597760ee2 100644 --- a/src/libcamera/include/utils.h +++ b/src/libcamera/include/utils.h @@ -33,6 +33,7 @@ namespace utils { const char *basename(const char *path); char *secure_getenv(const char *name); +std::string dirname(const std::string &path); template unsigned int set_overlap(InputIt1 first1, InputIt1 last1, diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp index 453e3b3b5995..3fd3aeaf822a 100644 --- a/src/libcamera/utils.cpp +++ b/src/libcamera/utils.cpp @@ -70,6 +70,23 @@ char *secure_getenv(const char *name) #endif } +/** + * \brief identify the dirname portion of a path + * \param[in] path The full path to parse + * + * \returns A string of the directory component of the path + */ +std::string dirname(const std::string &path) +{ + size_t pos = path.rfind('/', path.length()); + + if (pos != std::string::npos) { + return (path.substr(0, pos)); + } + + return path; +} + /** * \fn libcamera::utils::set_overlap(InputIt1 first1, InputIt1 last1, * InputIt2 first2, InputIt2 last2)