]> Savannah Git Hosting - gnulib.git/commitdiff
af_alg: minor style improvements
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 5 May 2018 18:08:08 +0000 (11:08 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 5 May 2018 18:11:16 +0000 (11:11 -0700)
* 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.

ChangeLog
lib/af_alg.c

index 6704802f95d558ebc540432687e57db7be543096..bdf18d44f147e029ad9d5045e8d24c5e4906bdec 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index 06344b1d602e8fb2d1d29870c70956d42f959af9..519d6f8f3e04a44133aa6e1f498a0e9daccd1e17 100644 (file)
 #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 @@ afalg_stream (FILE * stream, const char *alg, void *resblock, ssize_t hashlen)
     }
 
   /* 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 @@ afalg_stream (FILE * stream, const char *alg, void *resblock, ssize_t hashlen)
           ret = -EIO;
           goto out_ofd;
         }
-      else
-        ret = 0;
     }
   else
     {