public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Saleem Abdulrasool <abdulras@google.com>
To: elfutils-devel@sourceware.org
Subject: Re: [PATCH] handle libc implemntations which do not provide `error.h`
Date: Fri, 20 Aug 2021 13:23:42 -0700	[thread overview]
Message-ID: <CAO8XFHsk=H=xvS9gaPg-8s7TUKVVvaiw_HkCBDtxtn=ovE36zQ@mail.gmail.com> (raw)
In-Reply-To: <20210820182300.2842423-1-abdulras@google.com>

Hi,

Sorry, this change is missing a modification that I seemed to have
left out accidentally.  I missed the inclusion of `err.h` in the
`HAVE_ERR_H` when I was staging the changes locally.  I'll send out a
new version of this patch.


On Fri, Aug 20, 2021 at 11:23 AM Saleem Abdulrasool <abdulras@google.com> wrote:
>
> Introduce a configure time check for the presence of `error.h`.  In the
> case that `error.h` is not available, we can fall back to `err.h`.
> Although `err.h` is not a C standard header (it is a BSD extension),
> many libc implementations provide.  If there are targets which do not
> provide an implementation of `err.h`, it would be possible to further
> extend the implementation to be more portable.
>
> This resolves PR21008.
>
> Signed-off-by: Saleem Abdulrasool <abdulras@google.com>
> ---
>  configure.ac |  3 +++
>  lib/system.h | 23 ++++++++++++++++++++++-
>  2 files changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/configure.ac b/configure.ac
> index 7caff2c5..177bb1a2 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -431,6 +431,9 @@ AC_CHECK_DECLS([reallocarray],[],[],
>
>  AC_CHECK_FUNCS([process_vm_readv])
>
> +AC_CHECK_HEADERS([error.h])
> +AC_CHECK_HEADERS([err.h])
> +
>  old_CFLAGS="$CFLAGS"
>  CFLAGS="$CFLAGS -D_GNU_SOURCE"
>  AC_FUNC_STRERROR_R()
> diff --git a/lib/system.h b/lib/system.h
> index 58d9deee..8adb5848 100644
> --- a/lib/system.h
> +++ b/lib/system.h
> @@ -29,8 +29,9 @@
>  #ifndef LIB_SYSTEM_H
>  #define LIB_SYSTEM_H   1
>
> +#include <config.h>
> +
>  #include <errno.h>
> -#include <error.h>
>  #include <stddef.h>
>  #include <stdint.h>
>  #include <sys/param.h>
> @@ -40,6 +41,26 @@
>  #include <string.h>
>  #include <stdlib.h>
>
> +#if defined(HAVE_ERROR_H)
> +#include <error.h>
> +#elif defined(HAVE_ERR_H)
> +static int error_message_count = 0;
> +
> +static inline void error(int status, int errnum, const char *format, ...) {
> +  va_list argp;
> +
> +  va_start(argp, format);
> +  verr(status, format, argp);
> +  va_end(argp);
> +
> +  if (status)
> +    exit(status);
> +  ++error_message_count;
> +}
> +#else
> +#error "err.h or error.h must be available"
> +#endif
> +
>  #if __BYTE_ORDER == __LITTLE_ENDIAN
>  # define LE32(n)       (n)
>  # define LE64(n)       (n)
> --
> 2.33.0.rc2.250.ged5fa647cd-goog
>

      reply	other threads:[~2021-08-20 20:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-20 18:23 Saleem Abdulrasool
2021-08-20 20:23 ` Saleem Abdulrasool [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAO8XFHsk=H=xvS9gaPg-8s7TUKVVvaiw_HkCBDtxtn=ovE36zQ@mail.gmail.com' \
    --to=abdulras@google.com \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).