diff --git a/include/common/standard.h b/include/common/standard.h index eff47e749..2366f9e43 100644 --- a/include/common/standard.h +++ b/include/common/standard.h @@ -384,4 +384,10 @@ int word_match(const char *sample, int slen, const char *word, int wlen); */ int buf2ip(const char *buf, size_t len, struct in_addr *dst); +/* To be used to quote config arg positions. Returns the string at + * surrounded by simple quotes if is valid and non-empty, or "end of line" + * if ptr is NULL or empty. The string is locally allocated. + */ +const char *quote_arg(const char *ptr); + #endif /* _COMMON_STANDARD_H */ diff --git a/src/standard.c b/src/standard.c index 3f3e6bd0e..12954b0c7 100644 --- a/src/standard.c +++ b/src/standard.c @@ -1059,6 +1059,25 @@ int buf2ip(const char *buf, size_t len, struct in_addr *dst) return addr - cp; } +/* To be used to quote config arg positions. Returns the short string at + * surrounded by simple quotes if is valid and non-empty, or "end of line" + * if ptr is NULL or empty. The string is locally allocated. + */ +const char *quote_arg(const char *ptr) +{ + static char val[32]; + int i; + + if (!ptr || !*ptr) + return "end of line"; + val[0] = '\''; + for (i = 1; i < sizeof(val) - 1 && *ptr; i++) + val[i] = *ptr++; + val[i++] = '\''; + val[i] = '\0'; + return val; +} + /* * Local variables: * c-indent-level: 8