linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Goffredo Baroncelli <kreijack@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Goffredo Baroncelli <kreijack@inwind.it>
Subject: [PATCH 2/7] recursive btrfs sub snapshot/delete: create pathjoin() function
Date: Sat, 16 Nov 2013 18:09:02 +0100	[thread overview]
Message-ID: <1384621747-25441-3-git-send-email-kreijack@inwind.it> (raw)
In-Reply-To: <1384621747-25441-1-git-send-email-kreijack@inwind.it>

The pathjoin() function creates a path from a list of strings.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
---
 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 <linux/kdev_t.h>
 #include <limits.h>
 #include <blkid/blkid.h>
+#include <stdarg.h>
 #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
-- 
1.8.4.3


  parent reply	other threads:[~2013-11-16 17:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-16 17:09 [PATCH] BTRFS-PROG: recursively subvolume snapshot and delete Goffredo Baroncelli
2013-11-16 17:09 ` [PATCH 1/7] Recursive btrfs sub snapshot/delete: create get_root_info() function Goffredo Baroncelli
2013-11-16 17:09 ` Goffredo Baroncelli [this message]
2013-11-16 17:09 ` [PATCH 3/7] recursive btrfs snapshot/delete: create traverse_list_subvol_rec() Goffredo Baroncelli
2013-11-16 17:09 ` [PATCH 4/7] recursive btrfs subvol delete Goffredo Baroncelli
2013-11-16 17:09 ` [PATCH 5/7] recursively btrfs subvolume snapshot Goffredo Baroncelli
2013-11-16 17:09 ` [PATCH 6/7] btrfs subvolume snapshot -R: update man page Goffredo Baroncelli
2013-11-16 17:09 ` [PATCH 7/7] Document the -R switch for the "btrfs subvolume delete" command Goffredo Baroncelli
2013-11-25 21:23 ` [PATCH] BTRFS-PROG: recursively subvolume snapshot and delete Goffredo Baroncelli
2013-11-26 15:12   ` Konstantinos Skarlatos
2013-11-26 17:44     ` Goffredo Baroncelli
2013-11-27  9:15       ` Konstantinos Skarlatos
2013-11-27 17:04         ` Goffredo Baroncelli
2013-11-28 18:31 ` David Sterba
2013-11-28 19:23   ` Goffredo Baroncelli
2013-11-29 18:07     ` David Sterba
2013-11-29 19:09       ` Goffredo Baroncelli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1384621747-25441-3-git-send-email-kreijack@inwind.it \
    --to=kreijack@gmail.com \
    --cc=kreijack@inwind.it \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).