From: wysochanski@sourceware.org <wysochanski@sourceware.org>
To: lvm-devel@redhat.com
Subject: LVM2 ./WHATS_NEW lib/misc/lvm-string.c lib/mis ...
Date: 25 Apr 2007 18:24:19 -0000 [thread overview]
Message-ID: <20070425182419.23092.qmail@sourceware.org> (raw)
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski at sourceware.org 2007-04-25 19:24:19
Modified files:
. : WHATS_NEW
lib/misc : lvm-string.c lvm-string.h
Log message:
Add count_chars and count_chars_len functions, two
generic string utility functions.
--
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.601&r2=1.602
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/misc/lvm-string.c.diff?cvsroot=lvm2&r1=1.12&r2=1.13
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/misc/lvm-string.h.diff?cvsroot=lvm2&r1=1.13&r2=1.14
--- LVM2/WHATS_NEW 2007/04/25 14:49:27 1.601
+++ LVM2/WHATS_NEW 2007/04/25 18:24:19 1.602
@@ -1,5 +1,6 @@
Version 2.02.25 -
=================================
+ Add count_chars and count_chars_len functions
Add /sys/block listings to lvm_dump.sh
Make lvm_dump.sh list /dev recursively
Fix thread race in clvmd.
--- LVM2/lib/misc/lvm-string.c 2006/08/21 12:54:53 1.12
+++ LVM2/lib/misc/lvm-string.c 2007/04/25 18:24:19 1.13
@@ -36,18 +36,38 @@
}
/*
- * 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(const char *str, size_t *len, int *count,
+ const 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, const char c)
+{
+ int i;
+ unsigned count=0;
+
+ for (i=0; i < size; i++)
+ if (str[i] == c)
+ count++;
+ return count;
+
}
/*
@@ -73,11 +93,11 @@
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 +125,12 @@
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;
--- LVM2/lib/misc/lvm-string.h 2006/08/21 12:54:53 1.13
+++ LVM2/lib/misc/lvm-string.h 2007/04/25 18:24:19 1.14
@@ -30,4 +30,8 @@
int validate_name(const char *n);
+void count_chars(const char *str, size_t *len, int *count,
+ char c);
+unsigned count_chars_len(const char *str, size_t size, char c);
+
#endif
next reply other threads:[~2007-04-25 18:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-25 18:24 wysochanski [this message]
-- strict thread matches above, loose matches on Subject: below --
2010-11-17 10:19 LVM2 ./WHATS_NEW lib/misc/lvm-string.c lib/mis agk
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=20070425182419.23092.qmail@sourceware.org \
--to=wysochanski@sourceware.org \
--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.