util: provide the 'count_char' helper function.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2015-08-22 18:16:00 +02:00
parent e27b036d09
commit efa91dda77
3 changed files with 19 additions and 11 deletions

View File

@ -446,17 +446,6 @@ static enum parser_result parse_port_setting(struct config *cfg,
return parse_item(cfg, iface->name, option, value);
}
static int count_char(const char *str, char c)
{
int num = 0;
char s;
while ((s = *(str++))) {
if (s == c)
num++;
}
return num;
}
static enum parser_result parse_global_setting(const char *option,
const char *value,
struct config *cfg)

11
util.c
View File

@ -77,6 +77,17 @@ char *cid2str(struct ClockIdentity *id)
return buf;
}
int count_char(const char *str, char c)
{
int num = 0;
char s;
while ((s = *(str++))) {
if (s == c)
num++;
}
return num;
}
char *pid2str(struct PortIdentity *id)
{
static char buf[64];

8
util.h
View File

@ -44,6 +44,14 @@ extern const char *ev_str[];
*/
char *cid2str(struct ClockIdentity *id);
/**
* Counts the number of occurrences of a given character.
* @param str String to evaluate.
* @param c The character of interest.
* @return The number of time 'c' appears in 'str'.
*/
int count_char(const char *str, char c);
/**
* Convert a port identity into a human readable string.
*