changeset 39328:7559412d22f9

af_alg: minor style improvements * lib/af_alg.c (afalg_stream): Prefer C99 style decl-after-statement, since we’re already assuming C99. Clarify by strengthening the bind test and omit unnecessary assignment.
author Paul Eggert <eggert@cs.ucla.edu>
date Sat, 05 May 2018 11:08:08 -0700
parents 9b339d5a562b
children ee78086c564a
files ChangeLog lib/af_alg.c
diffstat 2 files changed, 16 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat May 05 20:02:58 2018 +0200
+++ b/ChangeLog	Sat May 05 11:08:08 2018 -0700
@@ -6,6 +6,11 @@
 
 2018-05-05  Paul Eggert  <eggert@cs.ucla.edu>
 
+	af_alg: minor style improvements
+	* lib/af_alg.c (afalg_stream): Prefer C99 style
+	decl-after-statement, since we’re already assuming C99.  Clarify
+	by strengthening the bind test and omit unnecessary assignment.
+
 	sys-limits.h: new file for crypto and safe I/O
 	* lib/af_alg.c: Include sys-limits.h.
 	(MAX_RW_COUNT): Remove.  Use replaced by SYS_BUFSIZE_MAX.
--- a/lib/af_alg.c	Sat May 05 20:02:58 2018 +0200
+++ b/lib/af_alg.c	Sat May 05 11:08:08 2018 -0700
@@ -35,32 +35,29 @@
 #define BLOCKSIZE 32768
 
 int
-afalg_stream (FILE * stream, const char *alg, void *resblock, ssize_t hashlen)
+afalg_stream (FILE *stream, const char *alg, void *resblock, ssize_t hashlen)
 {
+  int cfd = socket (AF_ALG, SOCK_SEQPACKET, 0);
+  if (cfd < 0)
+    return -EAFNOSUPPORT;
+
   struct sockaddr_alg salg = {
     .salg_family = AF_ALG,
     .salg_type = "hash",
   };
-  int ret, cfd, ofd;
-  struct stat st;
-
-  cfd = socket (AF_ALG, SOCK_SEQPACKET, 0);
-  if (cfd < 0)
-    return -EAFNOSUPPORT;
-
-  /* avoid calling both strcpy and strlen.  */
+  /* Avoid calling both strcpy and strlen.  */
   for (int i = 0; (salg.salg_name[i] = alg[i]); i++)
     if (i == sizeof salg.salg_name - 1)
       return -EINVAL;
 
-  ret = bind (cfd, (struct sockaddr *) &salg, sizeof salg);
-  if (ret < 0)
+  int ret = bind (cfd, (struct sockaddr *) &salg, sizeof salg);
+  if (ret != 0)
     {
       ret = -EAFNOSUPPORT;
       goto out_cfd;
     }
 
-  ofd = accept (cfd, NULL, 0);
+  int ofd = accept (cfd, NULL, 0);
   if (ofd < 0)
     {
       ret = -EAFNOSUPPORT;
@@ -68,7 +65,8 @@
     }
 
   /* if file is a regular file, attempt sendfile to pipe the data.  */
-  if (!fstat (fileno (stream), &st)
+  struct stat st;
+  if (fstat (fileno (stream), &st) == 0
       && (S_ISREG (st.st_mode) || S_TYPEISSHM (&st) || S_TYPEISTMO (&st))
       && 0 < st.st_size && st.st_size <= SYS_BUFSIZE_MAX)
     {
@@ -77,8 +75,6 @@
           ret = -EIO;
           goto out_ofd;
         }
-      else
-        ret = 0;
     }
   else
     {