From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <3ahAgYQgKDhs124LCI1J7FF7C5.3FD5C6LK9CJ-45M5CJFLI35N1I5.FI7@flex--abdulras.bounces.google.com> Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by sourceware.org (Postfix) with ESMTPS id B45E4385841D for ; Fri, 20 Aug 2021 20:28:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B45E4385841D Received: by mail-qt1-x84a.google.com with SMTP id x11-20020ac86b4b000000b00299d7592d31so5483575qts.0 for ; Fri, 20 Aug 2021 13:28:26 -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=0nfvcUJhO4ZLcRCsGyOPWW4xdcTG/icEPZSr26oOJNI=; b=rQUm/tsUPzxYMdZp2DNEqBM0g7TBup8QUNwmGDqms/TESvltwpWfEZ4YIg6TBpkDW0 ZfU0LcsoC+tk0fs9moG5guh4P0nXuu4fY2qZoDbhMhpGhVySIhSGvFsPXa1GJZQ9zOEH WTxH6ti0+w/IGg7cdGkW+fPqIU8xBTfU9ho3B59azVnEqkhqSK5QovxEptOk+v+pcTDs oyFz7QgvarkI7iXYNL14BZpthwzt+Jcbl6G2t9WYM48iCvH6vuGEnjIYloz9Wjz7U/mN La5L2cc/fk0wptmYkonzxBA6/iUxjW/jsGYmuRVxiewLj94fMSAsbMYWpoHwV3Sl+yRC tqKg== X-Gm-Message-State: AOAM531gjBiv5Ms8e1BQJyXIquXKyeFmqOaC7h/mlr6pMhrwNjFtPa0i Yvo3lsxquO2eG7pRiHagE5H8YMkI1xzbMJ249DeVgnEC/YwuOCPlNxCEXtSKV8RSONyEw5D/iE4 MS7xjfUTV59cq+xmpXcTgUGrP+kr1gl3vyXXbCsxZibRHgUkTjA62/2LtgDumDTrxJSX1SDxAYr JV X-Google-Smtp-Source: ABdhPJyYggLwJ73zKNBrJaoIYXo08rVnnPM4OS40wUZnmGNMlHRY2a1hWfm0rv7jUkb1AuFCQmEbupjFFD+lcQ== X-Received: from abdulras-llvm.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:219b]) (user=abdulras job=sendgmr) by 2002:a05:6214:10e6:: with SMTP id q6mr22352112qvt.11.1629491306296; Fri, 20 Aug 2021 13:28:26 -0700 (PDT) Date: Fri, 20 Aug 2021 20:28:23 +0000 Message-Id: <20210820202823.2865202-1-abdulras@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog Subject: [PATCH v2] 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, 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, 20 Aug 2021 20:28:37 -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 resolves bug #21008. Signed-off-by: Saleem Abdulrasool --- configure.ac | 3 +++ lib/system.h | 26 +++++++++++++++++++++++++- 2 files changed, 28 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..b963fd15 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,31 @@ #include #include #include +#include #include +#if defined(HAVE_ERROR_H) +#include +#elif defined(HAVE_ERR_H) +#include + +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