From: Dave Wysochanski <dwysocha@redhat.com>
To: lvm-devel@redhat.com
Subject: [PATCH REPOST2] convert _count_hyphens to generalised count_chars_null and export
Date: Mon, 23 Apr 2007 14:57:53 -0400 [thread overview]
Message-ID: <1177354673.4165.39.camel@linux-cxyg> (raw)
In-Reply-To: <1177089463.11574.0.camel@linux-cxyg>
Add count_chars_null and count_chars_len functions, two
generic string utility functions.
Index: LVM2-working2/lib/misc/lvm-string.c
===================================================================
--- LVM2-working2.orig/lib/misc/lvm-string.c 2006-08-21 08:54:53.000000000 -0400
+++ LVM2-working2/lib/misc/lvm-string.c 2007-04-23 14:48:56.000000000 -0400
@@ -36,18 +36,38 @@ 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.
+ * Count occurences of 'c' in 'str' until we reach a null char.
+ *
+ * Returns:
+ * len - incremented for each char we encounter, whether 'c' or not.
+ * count - number of occurences of 'c'
*/
-static void _count_hyphens(const char *str, size_t *len, int *hyphens)
+void count_chars_null(const char *str, size_t *len, int *count,
+ char c)
{
const char *ptr;
for (ptr = str; *ptr; ptr++, (*len)++)
- if (*ptr == '-')
- (*hyphens)++;
+ if (*ptr == c)
+ (*count)++;
+}
+
+/*
+ * Count occurences of 'c' in 'str' of length 'size'.
+ *
+ * Returns:
+ * # of occurences of 'c'
+ */
+unsigned count_chars_len(const char *str, size_t size, char c)
+{
+ int i;
+ unsigned count=0;
+
+ for (i=0; i<size; i++)
+ if (str[i] == c)
+ count++;
+ return count;
+
}
/*
@@ -73,11 +93,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_null(vgname, &len, &hyphens, '-');
+ count_chars_null(lvname, &len, &hyphens, '-');
if (layer && *layer) {
- _count_hyphens(layer, &len, &hyphens);
+ count_chars_null(layer, &len, &hyphens, '-');
hyphens++;
}
@@ -105,6 +125,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-working2/lib/misc/lvm-string.h
===================================================================
--- LVM2-working2.orig/lib/misc/lvm-string.h 2006-08-21 08:54:53.000000000 -0400
+++ LVM2-working2/lib/misc/lvm-string.h 2007-04-23 14:38:45.000000000 -0400
@@ -30,4 +30,8 @@ char *build_dm_name(struct dm_pool *mem,
int validate_name(const char *n);
+void count_chars_null(const char *str, size_t *len, int *count,
+ char c);
+unsigned count_chars_len(const char *str, size_t size, char c);
+
#endif
Index: LVM2-working2/WHATS_NEW
===================================================================
--- LVM2-working2.orig/WHATS_NEW 2007-04-23 14:21:01.000000000 -0400
+++ LVM2-working2/WHATS_NEW 2007-04-23 14:41:22.000000000 -0400
@@ -1,5 +1,6 @@
Version 2.02.25 -
=================================
+ Add count_chars_null and count_chars_len functions.
Add scan_sector param to label_read and _find_labeller.
Make clvmd cope with quorum devices on RHEL5
Add dev_read_circular.
prev parent reply other threads:[~2007-04-23 18:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-20 14:37 [PATCH] convert _count_hyphens to generalised _count_chars and export Dave Wysochanski
2007-04-20 15:06 ` [PATCH REPOST] convert _count_hyphens to generalised count_chars " Dave Wysochanski
2007-04-20 17:17 ` Dave Wysochanski
2007-04-23 18:57 ` Dave Wysochanski [this message]
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=1177354673.4165.39.camel@linux-cxyg \
--to=dwysocha@redhat.com \
--cc=lvm-devel@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.