public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jeff Law <law@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-1560] libiberty: writeargv: Simplify function error mode.
Date: Tue,  6 Jun 2023 03:11:19 +0000 (GMT)	[thread overview]
Message-ID: <20230606031119.831D53858416@sourceware.org> (raw)

https://gcc.gnu.org/g:4d1e4ce986f84a853531ac9c51e37d101e28d15c

commit r14-1560-g4d1e4ce986f84a853531ac9c51e37d101e28d15c
Author: Costas Argyris <costas.argyris@gmail.com>
Date:   Mon Jun 5 21:10:26 2023 -0600

    libiberty: writeargv: Simplify function error mode.
    
    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.
    
    0001-libiberty-writeargv-Simplify-function-error-mode.patch
    
    From 1271552baee5561fa61652f4ca7673c9667e4f8f Mon Sep 17 00:00:00 2001
    From: Costas Argyris <costas.argyris@gmail.com>
    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.
    
    libiberty/
            * argv.c (writeargv): Simplify & remove gotos.
    
    Signed-off-by: Costas Argyris <costas.argyris@gmail.com>

Diff:
---
 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;
 }

                 reply	other threads:[~2023-06-06  3:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230606031119.831D53858416@sourceware.org \
    --to=law@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.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).