Martin Ågren <martin.ag...@gmail.com> writes:

> I'm open for suggestions on the naming of `prefix_suffix_lines()`...

Is there a verb that means "have/place the thing in between two
other things" or "Bring two things and place them on each side of
the third thing" in a more concise way?  Wrap?  Sandwich?  Enclose?

> +
> +/*
> + * Write the message to the file, prefixing and suffixing
> + * each line with `prefix` resp. `suffix`.
> + */
> +void prefix_suffix_lines(FILE *f, const char *prefix,
> +                      const char *message, const char *suffix);
> +
> ...
> diff --git a/usage.c b/usage.c
> index cdd534c9df..80f9c1d14b 100644
> --- a/usage.c
> +++ b/usage.c
> @@ -6,6 +6,24 @@
>  #include "git-compat-util.h"
>  #include "cache.h"
>  
> +void prefix_suffix_lines(FILE *f,
> +                      const char *prefix,
> +                      const char *message,
> +                      const char *suffix)
> +{
> +     const char *cp, *np;
> +
> +     for (cp = message; *cp; cp = np) {
> +             np = strchrnul(cp, '\n');
> +             fprintf(f, "%s%.*s%s\n",
> +                     prefix,
> +                     (int)(np - cp), cp,
> +                     suffix);
> +             if (*np)
> +                     np++;
> +     }
> +}
> +
>  void vreportf(const char *prefix, const char *err, va_list params)
>  {
>       char msg[4096];

I guess we can directly use this even in the codepath that
implements die() without having to worry about the helper making any
extra allocation, which is good.


Reply via email to