From 12ee35f8275f94e080b6a990e7a4f87882282453 Mon Sep 17 00:00:00 2001 From: Milan Cejnar Date: Mon, 18 Feb 2013 10:09:12 +0100 Subject: tools: append new line to string from poptStrerror() https://fedorahosted.org/sssd/ticket/1756 Messages from poptStrerror() passed to BAD_POPT_PARAMS macro were printed out to the console without new line character at the end of the message. BAD_POPT_PARAMS should now behave correctly with strings both with or without new line character at the end. --- src/tools/tools_util.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/tools') diff --git a/src/tools/tools_util.c b/src/tools/tools_util.c index 731b2d04..85164c61 100644 --- a/src/tools/tools_util.c +++ b/src/tools/tools_util.c @@ -70,8 +70,20 @@ static int setup_db(struct tools_ctx *ctx) */ void usage(poptContext pc, const char *error) { + size_t lentmp; + char nl[2] = ""; + poptPrintUsage(pc, stderr, 0); - if (error) fprintf(stderr, "%s", error); + + if (error) { + lentmp = strlen(error); + if ((lentmp > 0) && (error[lentmp - 1] != '\n')) { + nl[0]='\n'; + nl[1]='\0'; + } + + fprintf(stderr, "%s%s", error, nl); + } } int parse_groups(TALLOC_CTX *mem_ctx, const char *optstr, char ***_out) -- cgit