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

Yuya Nishihara yuya at tcha.org
Tue Apr 5 12:00:30 EDT 2016


On Tue, 5 Apr 2016 16:52:38 +0100, Jun Wu wrote:
> On 04/05/2016 04:26 PM, Yuya Nishihara wrote:
> > Could you implement it more cleanly?  
> 
> Umm... I think it's a bit tricky. See comments below.
> 
> > - I know abortmsg() never return, but clearing errno here makes me feel bad.
> > - No need to use a preprocessor.  
> 
> Sorry but I'm trying to avoid code duplication. I cannot think of a better way
> than this.
> 
> Options I have thought:
> - Add a boolean parameter to abortmsg() to control whether to print errno.
>    Feels strange, inconsistent with other printf-alike functions
> - Check if fmt ends with "(errno)". Feels stupid since it's doing things
>    at runtime while could be done in compile time.
> - Extract common logic to abortmsghead(), abortmsgtail() etc. The va_list
>    part cannot be de-duplicated cleanly without preprocessor.

Hmm, vprintabortmsg(int eno, const char *fmt, va_list ap) ?
Never tried.

> > - One-char suffix "e" is hard to distinguish. How about aborterr() or
> > aborterrno()?
> 
> If we choose the long version, how about just abortmsgerrno ?

Sounds fine.


More information about the Mercurial-devel mailing list