util: provide the 'count_char' helper function.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>master
parent
e27b036d09
commit
efa91dda77
11
config.c
11
config.c
|
@ -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
11
util.c
|
@ -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
8
util.h
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue