]> Savannah Git Hosting - gnulib.git/commitdiff
af_alg: fix my typo in afalg_buffer
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 10 May 2018 01:28:04 +0000 (18:28 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 10 May 2018 01:30:59 +0000 (18:30 -0700)
* lib/af_alg.c (afalg_buffer): Fix typo I recently introduced.
(afalg_stream): Simplify and avoid the need for a runtime test
at the end.

ChangeLog
lib/af_alg.c

index 4eb0958583b9046a3d38321d5a20fb558ff04051..420426fe11c2a965486adca9f461aae68c1b9bad 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2018-05-09  Paul Eggert  <eggert@cs.ucla.edu>
 
+       af_alg: fix my typo in afalg_buffer
+       * lib/af_alg.c (afalg_buffer): Fix typo I recently introduced.
+       (afalg_stream): Simplify and avoid the need for a runtime test
+       at the end.
+
        af_alg: recover better from crypto failures
        * lib/af_alg.c (afalg_stream): Recover from crypto failures if the
        input stream is seekable, by repositioning the stream back to
index 677a8e34044e5ec770f3c9e4e4c0e75bafbaa346..ded4b326b7f883fc12a3f0c4bde4f6f822ec3f67 100644 (file)
@@ -86,7 +86,7 @@ afalg_buffer (const char *buffer, size_t len, const char *alg,
       len -= size;
       if (len == 0)
         {
-          result = read (ofd, resblock, hashlen) == hashlen ? -EAFNOSUPPORT: 0;
+          result = read (ofd, resblock, hashlen) == hashlen ? 0 : -EAFNOSUPPORT;
           break;
         }
     }
@@ -108,7 +108,7 @@ afalg_stream (FILE *stream, const char *alg,
      with /proc files that pretend to be empty, and lets the classic
      read-write loop work around an empty-input bug noted below.  */
   int fd = fileno (stream);
-  int result = 0;
+  int result;
   struct stat st;
   off_t nseek = 0, off = ftello (stream);
   if (0 <= off && fstat (fd, &st) == 0
@@ -116,8 +116,7 @@ afalg_stream (FILE *stream, const char *alg,
       && off < st.st_size && st.st_size - off < SYS_BUFSIZE_MAX)
     {
       off_t nbytes = st.st_size - off;
-      if (sendfile (ofd, fd, &off, nbytes) != nbytes)
-        result = -EAFNOSUPPORT;
+      result = sendfile (ofd, fd, &off, nbytes) == nbytes ? 0 : -EAFNOSUPPORT;
     }
   else
     {
@@ -132,17 +131,14 @@ afalg_stream (FILE *stream, const char *alg,
             {
               /* On Linux < 4.9, the value for an empty stream is wrong (all 0).
                  See <https://patchwork.kernel.org/patch/9308641/>.  */
-              if (nseek == 0)
-                result = -EAFNOSUPPORT;
-
-              if (ferror (stream))
-                result = -EIO;
+              result = ferror (stream) ? -EIO : nseek == 0 ? -EAFNOSUPPORT : 0;
               break;
             }
           nseek -= size;
           if (send (ofd, buf, size, MSG_MORE) != size)
             {
-              result = -EAFNOSUPPORT;
+              result = (fseeko (stream, nseek, SEEK_CUR) == 0
+                        ? -EAFNOSUPPORT : -EIO);
               break;
             }
         }
@@ -151,9 +147,6 @@ afalg_stream (FILE *stream, const char *alg,
   if (result == 0 && read (ofd, resblock, hashlen) != hashlen)
     result = -EAFNOSUPPORT;
   close (ofd);
-  if (result == -EAFNOSUPPORT && nseek != 0
-      && fseeko (stream, nseek, SEEK_CUR) != 0)
-    result = -EIO;
   return result;
 }