[lvm-devel] [PATCH REPOST] convert _count_hyphens to generalised count_chars and export
Dave Wysochanski
dwysocha at redhat.com
Fri Apr 20 15:06:52 UTC 2007
(NOTE: only change from previous patch - remove '_' from '_count_chars')
Should not change functional behavior and be simple to review.
Adds newly created function to lvm-string.h exports.
Index: LVM2/lib/misc/lvm-string.c
===================================================================
--- LVM2.orig/lib/misc/lvm-string.c 2007-04-20 10:31:14.000000000 -0400
+++ LVM2/lib/misc/lvm-string.c 2007-04-20 11:00:53.000000000 -0400
@@ -36,21 +36,6 @@ int emit_to_buffer(char **buffer, size_t
}
/*
- * Device layer names are all of the form <vg>-<lv>-<layer>, any
- * other hyphens that appear in these names are quoted with yet
- * another hyphen. The top layer of any device has no layer
- * name. eg, vg0-lvol0.
- */
-static void _count_hyphens(const char *str, size_t *len, int *hyphens)
-{
- const char *ptr;
-
- for (ptr = str; *ptr; ptr++, (*len)++)
- if (*ptr == '-')
- (*hyphens)++;
-}
-
-/*
* Copies a string, quoting hyphens with hyphens.
*/
static void _quote_hyphens(char **out, const char *src)
@@ -63,6 +48,17 @@ static void _quote_hyphens(char **out, c
}
}
+
+void count_chars(const char *str, size_t *len, int *count,
+ char c)
+{
+ const char *ptr;
+
+ for (ptr = str; *ptr; ptr++, (*len)++)
+ if (*ptr == c)
+ (*count)++;
+}
+
/*
* <vg>-<lv>-<layer> or if !layer just <vg>-<lv>.
*/
@@ -73,11 +69,11 @@ char *build_dm_name(struct dm_pool *mem,
int hyphens = 1;
char *r, *out;
- _count_hyphens(vgname, &len, &hyphens);
- _count_hyphens(lvname, &len, &hyphens);
+ count_chars(vgname, &len, &hyphens, '-');
+ count_chars(lvname, &len, &hyphens, '-');
if (layer && *layer) {
- _count_hyphens(layer, &len, &hyphens);
+ count_chars(layer, &len, &hyphens, '-');
hyphens++;
}
@@ -105,6 +101,12 @@ char *build_dm_name(struct dm_pool *mem,
return r;
}
+/*
+ * Device layer names are all of the form <vg>-<lv>-<layer>, any
+ * other hyphens that appear in these names are quoted with yet
+ * another hyphen. The top layer of any device has no layer
+ * name. eg, vg0-lvol0.
+ */
int validate_name(const char *n)
{
register char c;
Index: LVM2/lib/misc/lvm-string.h
===================================================================
--- LVM2.orig/lib/misc/lvm-string.h 2007-04-20 10:31:14.000000000 -0400
+++ LVM2/lib/misc/lvm-string.h 2007-04-20 11:01:06.000000000 -0400
@@ -30,4 +30,7 @@ char *build_dm_name(struct dm_pool *mem,
int validate_name(const char *n);
+void count_chars(const char *str, size_t *len, int *count,
+ char c);
+
#endif
Index: LVM2/WHATS_NEW
===================================================================
--- LVM2.orig/WHATS_NEW 2007-04-20 10:31:14.000000000 -0400
+++ LVM2/WHATS_NEW 2007-04-20 11:05:29.000000000 -0400
@@ -1,5 +1,6 @@
Version 2.02.25 -
=================================
+ Convert _count_hyphens to generalized count_chars.
Add dev_read_circular.
Add pvck command stub.
Update lists of attribute characters in man pages.
More information about the lvm-devel
mailing list