From patchwork Sat Nov 16 17:09:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 3192931 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A34A0C045B for ; Sat, 16 Nov 2013 17:09:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CB8A7208BD for ; Sat, 16 Nov 2013 17:09:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E8A56207BF for ; Sat, 16 Nov 2013 17:09:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752279Ab3KPRJ1 (ORCPT ); Sat, 16 Nov 2013 12:09:27 -0500 Received: from mail-wi0-f177.google.com ([209.85.212.177]:54865 "EHLO mail-wi0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751222Ab3KPRJP (ORCPT ); Sat, 16 Nov 2013 12:09:15 -0500 Received: by mail-wi0-f177.google.com with SMTP id hq4so2236641wib.16 for ; Sat, 16 Nov 2013 09:09:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sU4MGQ5fNF7h9/tWkZ8k/uG//0omTGKtbuJT1O5FJDs=; b=P7MaAwa3+Tdyydy9JsosouM6yEI1GoJJq9YCWdw6AD7IMvK6JRQeg93n8O0Y3MucqM ftcI4Y+4TMRWK6tcyk5SmUTebnr+b3imHjXbL5utqijYeOvMuRX8cxiacetnk+suilxb E0PXXidWReoRsyGGWBZfrReP3cbymjl2GfpEfHot9mHXwSxJzIZ+R9Klvinszo3b81Xl wlKApETKoWJhdQy0ZThnhPEnvhcTh3yR73a4EUb8QwaVgI5955iIHy4sy+VZFIgDNKqB KpSDwgOl2FQXx+CVlCGYmVrIDFaIGVetQu91G7F7+FD9SnPJXFvvAkiDL3ShdNSS5a3w w5Rw== X-Received: by 10.180.219.75 with SMTP id pm11mr11225996wic.21.1384621754197; Sat, 16 Nov 2013 09:09:14 -0800 (PST) Received: from venice.bhome (ppp-80-52.24-151.libero.it. [151.24.52.80]) by mx.google.com with ESMTPSA id e1sm6584799wij.6.2013.11.16.09.09.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 Nov 2013 09:09:13 -0800 (PST) From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Cc: Goffredo Baroncelli Subject: [PATCH 2/7] recursive btrfs sub snapshot/delete: create pathjoin() function Date: Sat, 16 Nov 2013 18:09:02 +0100 Message-Id: <1384621747-25441-3-git-send-email-kreijack@inwind.it> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1384621747-25441-1-git-send-email-kreijack@inwind.it> References: <1384621747-25441-1-git-send-email-kreijack@inwind.it> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The pathjoin() function creates a path from a list of strings. Signed-off-by: Goffredo Baroncelli --- utils.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ utils.h | 1 + 2 files changed, 64 insertions(+) diff --git a/utils.c b/utils.c index f499023..5f4d0ef 100644 --- a/utils.c +++ b/utils.c @@ -38,6 +38,7 @@ #include #include #include +#include #include "kerncompat.h" #include "radix-tree.h" #include "ctree.h" @@ -2108,3 +2109,65 @@ int lookup_ino_rootid(int fd, u64 *rootid) return 0; } + +/* + * Joints a list of string. The list has to be NULL terminated + */ +char *pathjoin( char *s, ...) +{ + va_list ap; + int size; + char *dst; + + if (!s || !strlen(s)) + return NULL; + + size = strlen(s)+1; + va_start(ap, s); + + do { + char *p; + + p = va_arg(ap, char *); + if (!p) + break; + + size += strlen(p)+1; + } while(1); + + va_end(ap); + size++; + + dst = malloc(size); + if (!dst) + return NULL; + + strcpy(dst, s); + va_start(ap, s); + + do { + char *p; + int l, l2; + p = va_arg(ap, char *); + if (!p) + break; + if (*p == '/') + p++; + + l2 = strlen(p); + if (!l2) + continue; + if (p[l2-1] == '/') + p[l2-1] = 0; + + l = strlen(dst); + if (dst[l-1] != '/') + strcat(dst, "/"); + strcat(dst, p); + + } while(1); + va_end(ap); + + return dst; + +} \ No newline at end of file diff --git a/utils.h b/utils.h index 6f4b10c..d6c52a6 100644 --- a/utils.h +++ b/utils.h @@ -94,5 +94,6 @@ int ask_user(char *question); int lookup_ino_rootid(int fd, u64 *rootid); int btrfs_scan_lblkid(int update_kernel); int get_btrfs_mount(const char *dev, char *mp, size_t mp_size); +char *pathjoin(char *, ...); #endif