[PATCH 1 of 3 V2] chg: add util function abortmsgerrno to print error with errno

timeless timeless at gmail.com
Tue Apr 5 14:04:03 EDT 2016


I'm not sure about chg, but for hg, adding a public symbol like this should
be flagged as API.
On Apr 5, 2016 12:50 PM, "Jun Wu" <quark at fb.com> wrote:

> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1459873539 -3600
> #      Tue Apr 05 17:25:39 2016 +0100
> # Node ID ff4f30f94e7d54bd36ed4a8a06faa99a0ac44298
> # Parent  1e97bcbb87767e1a96909900595a0b6a7791407b
> chg: add util function abortmsgerrno to print error with errno
>
> It's common to abortmsg with the errno information. Let's make a utility
> function for it.
>
> diff --git a/contrib/chg/util.c b/contrib/chg/util.c
> --- a/contrib/chg/util.c
> +++ b/contrib/chg/util.c
> @@ -7,6 +7,7 @@
>   * GNU General Public License version 2 or any later version.
>   */
>
> +#include <errno.h>
>  #include <signal.h>
>  #include <stdarg.h>
>  #include <stdio.h>
> @@ -27,18 +28,33 @@
>         fprintf(fp, "\033[%sm", code);
>  }
>
> +static void vabortmsgerrno(int no, const char *fmt, va_list args)
> +{
> +       fsetcolor(stderr, "1;31");
> +       fputs("chg: abort: ", stderr);
> +       vfprintf(stderr, fmt, args);
> +       if (no != 0)
> +               fprintf(stderr, " (errno = %d, %s)", no, strerror(no));
> +       fsetcolor(stderr, "");
> +       fputc('\n', stderr);
> +       exit(255);
> +}
> +
>  void abortmsg(const char *fmt, ...)
>  {
>         va_list args;
>         va_start(args, fmt);
> -       fsetcolor(stderr, "1;31");
> -       fputs("chg: abort: ", stderr);
> -       vfprintf(stderr, fmt, args);
> -       fsetcolor(stderr, "");
> -       fputc('\n', stderr);
> +       vabortmsgerrno(0, fmt, args);
>         va_end(args);
> +}
>
> -       exit(255);
> +void abortmsgerrno(const char *fmt, ...)
> +{
> +       int no = errno;
> +       va_list args;
> +       va_start(args, fmt);
> +       vabortmsgerrno(no, fmt, args);
> +       va_end(args);
>  }
>
>  static int debugmsgenabled = 0;
> diff --git a/contrib/chg/util.h b/contrib/chg/util.h
> --- a/contrib/chg/util.h
> +++ b/contrib/chg/util.h
> @@ -17,6 +17,7 @@
>  #endif
>
>  void abortmsg(const char *fmt, ...) PRINTF_FORMAT_;
> +void abortmsgerrno(const char *fmt, ...) PRINTF_FORMAT_;
>
>  void enablecolor(void);
>  void enabledebugmsg(void);
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20160405/cdabc37f/attachment.html>


More information about the Mercurial-devel mailing list