From efa91dda772e1dae88128782cd48de578e651ad6 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sat, 22 Aug 2015 18:16:00 +0200 Subject: [PATCH] util: provide the 'count_char' helper function. Signed-off-by: Richard Cochran --- config.c | 11 ----------- util.c | 11 +++++++++++ util.h | 8 ++++++++ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/config.c b/config.c index cc4e0f2..3190ad2 100644 --- a/config.c +++ b/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) diff --git a/util.c b/util.c index 1fa8336..9202c55 100644 --- a/util.c +++ b/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]; diff --git a/util.h b/util.h index 734ea05..758ee5f 100644 --- a/util.h +++ b/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. *