[PATCH 2 of 3] chg: add util function abortmsge to print error with errno

timeless timeless at gmail.com
Tue Apr 5 14:02:00 EDT 2016


Fwiw, you're removing a published symbol. This should be (API).

As the person who tends to have to fix things up after API breaks, I'm -1
on removing symbols to replace then with macros.
On Apr 5, 2016 10:22 AM, "Jun Wu" <quark at fb.com> wrote:

> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1459865259 -3600
> #      Tue Apr 05 15:07:39 2016 +0100
> # Node ID 6b037b1f423c08785c7c1abe3751f3be1fe550ed
> # Parent  704d3febf4b7ea1063c2c3a58788de13fea31e79
> chg: add util function abortmsge to print error with errno
>
> It's common to abort with the errno information. Let's make it a utility
> function.
>
> 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,13 +28,15 @@
>         fprintf(fp, "\033[%sm", code);
>  }
>
> -void abortmsg(const char *fmt, ...)
> +void abortmsge(const char *fmt, ...)
>  {
>         va_list args;
>         va_start(args, fmt);
>         fsetcolor(stderr, "1;31");
>         fputs("chg: abort: ", stderr);
>         vfprintf(stderr, fmt, args);
> +       if (errno != 0)
> +               fprintf(stderr, " (errno = %d, %s)", errno,
> strerror(errno));
>         fsetcolor(stderr, "");
>         fputc('\n', stderr);
>         va_end(args);
> diff --git a/contrib/chg/util.h b/contrib/chg/util.h
> --- a/contrib/chg/util.h
> +++ b/contrib/chg/util.h
> @@ -16,7 +16,8 @@
>  #define PRINTF_FORMAT_
>  #endif
>
> -void abortmsg(const char *fmt, ...) PRINTF_FORMAT_;
> +void abortmsge(const char *fmt, ...) PRINTF_FORMAT_;
> +#define abortmsg(...) { errno = 0; abortmsge(__VA_ARGS__); }
>
>  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/817c6469/attachment.html>


More information about the Mercurial-devel mailing list