From patchwork Mon Jun 5 14:37:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Costas Argyris X-Patchwork-Id: 103303 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2731788vqr; Mon, 5 Jun 2023 07:38:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4NdqbovJV6V5lZiOng5QuXbK736K5EdkEFtzE9YylrbTLNKAlI7BXd+8DI/0giuePwFgxy X-Received: by 2002:a17:906:7950:b0:977:d027:eeb9 with SMTP id l16-20020a170906795000b00977d027eeb9mr4517362ejo.35.1685975916771; Mon, 05 Jun 2023 07:38:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685975916; cv=none; d=google.com; s=arc-20160816; b=XbLeb6WuxwEoybM3cviLVu3c4L7m0W+mvAZ72ZlqNibZ9HN/mwv3ryw1oO1hoJZSCh 82D2yhg8YbT319LEqWVAkrJ09FIX8My/x0DXha/WMaE723VmBghihiM9boDCqJx1jqVD hfh6o4prEU4TDqI/XlgtTPIst7lVXnkKbhvs+R0/R94uRiGngjFs9NDv0WmILWHBYsoO nCJSPf3rbQ04sqG3RuIksksNP6w3PsQuk1BMtwOPSUyVO0pN7lvN/XEo4DKRvCTE4aS0 dcS+hnO9ydoYXjjBb/Y2OArL9UIKMeYKDKFBBI68+jn5/H3AdmkCMUVVLqL+e3CTCjKs e55w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:to:subject :message-id:date:mime-version:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=qM3jFAN3cIwuvj8F6UL2bz5nJilnJMlZXkDFR2cQzVE=; b=YSCVGbvTEgqQs5c7MQDLuCG2P8oTbijtN/Hv4Ov90bKDwLF3w9KiuxwVVtloqYbumI NSNuWl1vKqK6yv3FFoAfxgbQ/inKAJCHVhWA9U5R/SAPLgVCfxJSfyrrqV1Y3eo8GOEE tGYjg0pMVfYkOyyhmkmdaj+uauTIBfnuawFIpmwhmrbZzPcoXWZr8hCdCYbsi8eThKHZ 0EOKlQ/o2cr9QKv8bvwnL0LLy7PKTnyvhfcN/2jfs5L6a9kVBDcGjmEArSJEy6F+qnkL 47c9vDEWd2JV+huEWn+u26IBj8SJDj/dFrgOUDdwAYu8GE/eJamwAzbYCkKFXiMGtuL5 z5NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NNtj+xXb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gt18-20020a170906f21200b009661752287dsi4756557ejb.219.2023.06.05.07.38.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jun 2023 07:38:36 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NNtj+xXb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 598ED3881D3E for ; Mon, 5 Jun 2023 14:38:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 598ED3881D3E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685975915; bh=qM3jFAN3cIwuvj8F6UL2bz5nJilnJMlZXkDFR2cQzVE=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=NNtj+xXbbVCXuLad8zqBnXTSac1vSBCiy/4DLiJ9s3UCoql2wV8jqdWUAiZxSQGQk YamLIlgtCSI2A3K1341TDgfw0r60eXIox54O3w6yw9ol0tOrnOuvYfPyl0sk70JVS7 LhJimcUN/wZSfwyYwK3SvNKsl6bTjN4aAaXiTuA0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by sourceware.org (Postfix) with ESMTPS id CB10A388200C for ; Mon, 5 Jun 2023 14:37:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB10A388200C Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-51478f6106cso7446690a12.1 for ; Mon, 05 Jun 2023 07:37:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685975869; x=1688567869; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=vcw4FMK9VdtD41+/u1x355kltI38rVvHtLILe/nJbPA=; b=bmQ9XuwIWWliWHuww+YVE1Ra2F5him5wpFRpFrAYIU9//FplRQnMittGSy5OIDkw/w QjX7oqxMTjlSPeIHX2+FBlK3zj45o9wd9uSKKf86OB/OZFF+HWYf4ZutoAwWbEI1vbY1 eoJyW2bgAPKEqIiJPMGnayw8/pu/herAETn/sMmALEXAN/ZnzmQ/OABS2Kvx8pAZg44x nnPmegl+ik1hbQVshykL6xoVnHYUBKXz8iSaTBIm77xwgEp5txYatdZxDkGOMX8Je9ii LlJLYOL6DMvVNMqzPHyuHWEROUtWRa/NThglm1D/HNUyjkLi4s0GLeKfQgQBW1znfDgK l8aQ== X-Gm-Message-State: AC+VfDz+GFkRQPy4TregI3Zn51RBnbNP2jPGGL0bdZDe/8PTSfqg2yix zEh8yw6ISQLNLySDHbGd0PCwgcM/XfsEjlsmMR/rNmgN43Y= X-Received: by 2002:aa7:d392:0:b0:515:1e50:5498 with SMTP id x18-20020aa7d392000000b005151e505498mr7624595edq.15.1685975868963; Mon, 05 Jun 2023 07:37:48 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 5 Jun 2023 15:37:37 +0100 Message-ID: Subject: [PATCH] libiberty: writeargv: Simplify function error mode. To: gcc-patches@gcc.gnu.org X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Costas Argyris via Gcc-patches From: Costas Argyris Reply-To: Costas Argyris Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767873882961857707?= X-GMAIL-MSGID: =?utf-8?q?1767873882961857707?= writeargv can be simplified by getting rid of the error exit mode that was only relevant many years ago when the function used to open the file descriptor internally. From 1271552baee5561fa61652f4ca7673c9667e4f8f Mon Sep 17 00:00:00 2001 From: Costas Argyris Date: Mon, 5 Jun 2023 15:02:06 +0100 Subject: [PATCH] libiberty: writeargv: Simplify function error mode. The goto-based error mode was based on a previous version of the function where it was responsible for opening the file, so it had to close it upon any exit: https://inbox.sourceware.org/gcc-patches/20070417200340.GM9017@sparrowhawk.codesourcery.com/ (thanks pinskia) This is no longer the case though since now the function takes the file descriptor as input, so the exit mode on error can be just a simple return 1 statement. Signed-off-by: Costas Argyris --- libiberty/argv.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/libiberty/argv.c b/libiberty/argv.c index a95a10e14ff..1a18b4d8866 100644 --- a/libiberty/argv.c +++ b/libiberty/argv.c @@ -289,8 +289,8 @@ char **buildargv (const char *input) @deftypefn Extension int writeargv (char * const *@var{argv}, FILE *@var{file}) Write each member of ARGV, handling all necessary quoting, to the file -named by FILE, separated by whitespace. Return 0 on success, non-zero -if an error occurred while writing to FILE. +associated with FILE, separated by whitespace. Return 0 on success, +non-zero if an error occurred while writing to FILE. @end deftypefn @@ -314,36 +314,25 @@ writeargv (char * const *argv, FILE *f) if (ISSPACE(c) || c == '\\' || c == '\'' || c == '"') if (EOF == fputc ('\\', f)) - { - status = 1; - goto done; - } + return 1; if (EOF == fputc (c, f)) - { - status = 1; - goto done; - } + return 1; + arg++; } /* Write out a pair of quotes for an empty argument. */ if (arg == *argv) - if (EOF == fputs ("\"\"", f)) - { - status = 1; - goto done; - } + if (EOF == fputs ("\"\"", f)) + return 1; if (EOF == fputc ('\n', f)) - { - status = 1; - goto done; - } + return 1; + argv++; } - done: return status; } -- 2.30.2