From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <3WAYpYQgKDhkz02JAGzH5DD5A3.1DB3A4JI7AH-23K3AHDJG13LzG3.DG5@flex--abdulras.bounces.google.com> Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by sourceware.org (Postfix) with ESMTPS id AD68F3858C60 for ; Fri, 27 Aug 2021 15:35:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AD68F3858C60 Received: by mail-pj1-x104a.google.com with SMTP id nn5-20020a17090b38c500b00179d350674aso132750pjb.5 for ; Fri, 27 Aug 2021 08:35:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=5c9qZlxiv8pS2NhsRBBVDfeo5FYt7pCFWFau1t51Dcw=; b=j7GxHh0sYSY2+s1ECrMa6eEFB8Y2Yd0s54YvkStm97+FFlbiEx0swrJLKOwrIfXXXG 4T+6n6jgS1FgovU+5Wk918tuE0MEMpCsammlAOICHmgzsUXCGEOFHxVRdMyxiKPf19KJ 4Ve0TuPwZMAjcUcy/ZIHaU4/1cjFzVpYUZAcMJAg5Pw3FkjQBaOCpW8BicirGXncO+MB V/DP2FgWmLE6Ap9pdFFvrpdGPT97UM+wRgxcr/lEMceYjM80GPGHpHQoZQkUq7nCBVbt SpllFTRVZju+d1FjcAx/qPRrBppHqnIqfLFnkO9PXOX6g5L5BLhHw5tLxZj06rYSOxrl 03eg== X-Gm-Message-State: AOAM533Ru8Gl4d5mE7mbc4Qdnl8cx+cGkqN0mjuQcnbNgWZCsv3tj+IN r35Vf36MN3SL6mpIO4xLPmTdfvmx8PIoeeLTPV2j828RevZb9WFTJFpb7s6cXNuargSbuHGrNhF zIVWSA86qExA4yCt2GNf3MmVrrc/0xgizMqbZ3mui+L4OW/F5xHL6cm/iLVFZ8kHK9yyJy14c1K ZQ X-Google-Smtp-Source: ABdhPJypUamf488ZCx0JgcKpgymF8x/jIhq/VrcRtXf419J5EWQQoPd5FXLjMzo0No4XHHt46v5kvnMwWNJz0g== X-Received: from abdulras-llvm.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:219b]) (user=abdulras job=sendgmr) by 2002:a65:534b:: with SMTP id w11mr8471848pgr.141.1630078552633; Fri, 27 Aug 2021 08:35:52 -0700 (PDT) Date: Fri, 27 Aug 2021 15:35:49 +0000 Message-Id: <20210827153549.4065315-1-abdulras@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.259.gc128427fd7-goog Subject: [PATCH v3] handle libc implemntations which do not provide `error.h` From: Saleem Abdulrasool To: elfutils-devel@sourceware.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-21.4 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Aug 2021 15:36:04 -0000 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 partially resolves bug #21008. Signed-off-by: Saleem Abdulrasool --- configure.ac | 3 +++ lib/ChangeLog | 7 +++++++ lib/Makefile.am | 2 +- lib/error.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/system.h | 13 ++++++++++++- 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 lib/error.c 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/ChangeLog b/lib/ChangeLog index a95f8041..101a4e6f 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,10 @@ +2021-08-20 Saleem Abdulrasool + + * error.c: New file, adds error_number_count and error fallbacks. + * system.h: Declare error_number_count and error fallbacks for when + error.h is unavailable. + * Makefile.am (libeu_a_SOURCES): add error.c. + 2021-08-20 Saleem Abdulrasool * fixedsizehash.h: Remove sys/cdefs.h include. Unconditionally diff --git a/lib/Makefile.am b/lib/Makefile.am index 97bf7329..766fbcd7 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -35,7 +35,7 @@ noinst_LIBRARIES = libeu.a libeu_a_SOURCES = xstrdup.c xstrndup.c xmalloc.c next_prime.c \ crc32.c crc32_file.c \ - color.c printversion.c + color.c error.c printversion.c noinst_HEADERS = fixedsizehash.h libeu.h system.h dynamicsizehash.h list.h \ eu-config.h color.h printversion.h bpf.h \ diff --git a/lib/error.c b/lib/error.c new file mode 100644 index 00000000..b0264efb --- /dev/null +++ b/lib/error.c @@ -0,0 +1,49 @@ +/* Definitions for error handling fallback functions. + Copyright (C) 2021 Google, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of either + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at + your option) any later version + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at + your option) any later version + + or both in parallel, as here. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see . */ + +#include + +#if !defined(HAVE_ERROR_H) && defined(HAVE_ERR_H) +#include +#include +#include + +unsigned int error_message_count = 0; + +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; +} +#endif diff --git a/lib/system.h b/lib/system.h index 58d9deee..edbc8488 100644 --- a/lib/system.h +++ b/lib/system.h @@ -29,8 +29,9 @@ #ifndef LIB_SYSTEM_H #define LIB_SYSTEM_H 1 +#include + #include -#include #include #include #include @@ -38,8 +39,18 @@ #include #include #include +#include #include +#if defined(HAVE_ERROR_H) +#include +#elif defined(HAVE_ERR_H) +extern int error_message_count; +void error(int status, int errnum, const char *format, ...); +#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.259.gc128427fd7-goog