From patchwork Thu Oct 20 18:25:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonggang Luo X-Patchwork-Id: 59232 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BB3E4388302D for ; Thu, 20 Oct 2022 18:27:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB3E4388302D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666290448; bh=7fgEYu6qXaDPRDHYyYp7/B7V8pL4CCh3RRUc906CqbY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:From; b=mxmuz96fsw+ITB2zmSlAD+X1PwGqAVLUlL3+WXmNNtw4kI+zUSzaV6PajZz8UTBGG WDqNq5jrhT9RHmeN5x3tLM1RAwIdNBzWNx7y4ZGkmaKSLrWNacaEFV1UBXEUpGvrXX rHq4SS+PkAsH6GEbzteQOyQw65OJ/QJ72vjzbNJ4= X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by sourceware.org (Postfix) with ESMTPS id 2FE683865C28 for ; Thu, 20 Oct 2022 18:26:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2FE683865C28 Received: by mail-pj1-x1031.google.com with SMTP id o17-20020a17090aac1100b0020d98b0c0f4so4300495pjq.4 for ; Thu, 20 Oct 2022 11:26:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7fgEYu6qXaDPRDHYyYp7/B7V8pL4CCh3RRUc906CqbY=; b=ardnAewvAEqypcXXeoD9kvV0gxXQwj2ZNqjq0fg4gE43UxMkJqd6lqIRh4cQnJ6O0q FG0CY3kMPdMtuPgsV3a4UiSNXbAaksXgMT5IUuyx4CZBL7J9Z9kaqhHp/vicG2XB8lry 1tb/Cm73vKEaZ9UiQW785ZsqxMlZgCyPAmAoQ33wFLR1MdOohY5Tx7gdFFE63ZXRMlFf vYTXWXyXNNfp6x7+hpVZ+Iql+CrbMvw07sZaUWxsxmms/z6yreLpjukNLmipioFy01Lv RdQ1m3Em7dONI6dmpue/JaarwdAgtsseFM4zDg+c9P701DRN1ToBdqqzVB/I0ACLjt0A RMOw== X-Gm-Message-State: ACrzQf05ndGudOrxnbg+XyTnzZrs03XsYNAdawvXSBlZ9HrUMMByn6TV fErFdVbeRlUFoH2Xzxcs9MPkWwf05IzxyQ== X-Google-Smtp-Source: AMsMyM5j8NwBw2nr2bumwkIfgLfLGeaNVvXq74APS/TrQIgsy7+FWFk9YyDuBxbmxMNqXwk7eromlw== X-Received: by 2002:a17:903:2306:b0:185:43a2:3d1c with SMTP id d6-20020a170903230600b0018543a23d1cmr15336293plh.154.1666290415441; Thu, 20 Oct 2022 11:26:55 -0700 (PDT) Received: from localhost.localdomain ([103.94.185.75]) by smtp.googlemail.com with ESMTPSA id w15-20020a17090a460f00b00202fbd9c21dsm115067pjg.48.2022.10.20.11.26.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 11:26:54 -0700 (PDT) To: elfutils-devel@sourceware.org Subject: [PATCH 15/25] lib: Implement error properly even when not HAVE_ERR_H Date: Fri, 21 Oct 2022 02:25:54 +0800 Message-Id: <20221020182603.815-16-luoyonggang@gmail.com> X-Mailer: git-send-email 2.36.1.windows.1 In-Reply-To: <20221020182603.815-1-luoyonggang@gmail.com> References: <20221020182603.815-1-luoyonggang@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Yonggang Luo via Elfutils-devel From: Yonggang Luo Reply-To: Yonggang Luo Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" on win32, there is no err.h Signed-off-by: Yonggang Luo --- lib/error.c | 9 ++++++++- lib/system.h | 4 +--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/error.c b/lib/error.c index 5186fc15..7924735e 100644 --- a/lib/error.c +++ b/lib/error.c @@ -28,12 +28,14 @@ #include -#if !defined(HAVE_ERROR_H) && defined(HAVE_ERR_H) +#if !defined(HAVE_ERROR_H) #include #include #include #include +#if defined(HAVE_ERR_H) #include +#endif unsigned int error_message_count = 0; @@ -44,6 +46,7 @@ void error(int status, int errnum, const char *format, ...) { fflush (stdout); va_start(argp, format); +#if defined(HAVE_ERR_H) if (status) { if (errnum) @@ -64,6 +67,10 @@ void error(int status, int errnum, const char *format, ...) { else vwarnx (format, argp); } +#else + (void)status; + vfprintf(stderr, format, argp); +#endif va_end(argp); fflush (stderr); diff --git a/lib/system.h b/lib/system.h index 7132cd6d..264781c2 100644 --- a/lib/system.h +++ b/lib/system.h @@ -51,11 +51,9 @@ #if defined(HAVE_ERROR_H) #include -#elif defined(HAVE_ERR_H) +#else 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 /* error (EXIT_FAILURE, ...) should be noreturn but on some systems it