mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
Add count_chars and count_chars_len functions, two
generic string utility functions. --
This commit is contained in:
parent
69e0f4039f
commit
15309c57bd
@ -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.
|
||||
|
@ -36,18 +36,38 @@ int emit_to_buffer(char **buffer, size_t *size, const char *fmt, ...)
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 @@ char *build_dm_name(struct dm_pool *mem, const char *vgname,
|
||||
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 @@ char *build_dm_name(struct dm_pool *mem, const char *vgname,
|
||||
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;
|
||||
|
@ -30,4 +30,8 @@ char *build_dm_name(struct dm_pool *mem, const char *vg,
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user