]> Savannah Git Hosting - gnulib.git/commitdiff
af_alg: distiguish I/O errors better
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 9 May 2018 19:04:37 +0000 (12:04 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 9 May 2018 19:05:03 +0000 (12:05 -0700)
* lib/af_alg.c (afalg_buffer, afalg_stream): Return -EAFNOSUPPORT,
not -EIO, if it’s OK for the caller to try again with user-mode code.
(afalg_stream) [!_WIN32 || __CYGWIN__]: Return -EIO (not possibly
some other error number) if fflush fails, as the caller should not
try again that case.

ChangeLog
lib/af_alg.c

index 9c40bd672a1ef91202146d17e1e7ea848e4b5ffc..3a9dc63ec4f489ab1cc3126f8f2485d8f3f420a2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2018-05-09  Paul Eggert  <eggert@cs.ucla.edu>
 
+       af_alg: distiguish I/O errors better
+       * lib/af_alg.c (afalg_buffer, afalg_stream): Return -EAFNOSUPPORT,
+       not -EIO, if it’s OK for the caller to try again with user-mode code.
+       (afalg_stream) [!_WIN32 || __CYGWIN__]: Return -EIO (not possibly
+       some other error number) if fflush fails, as the caller should not
+       try again that case.
+
        af_alg: avoid gotos
        * lib/af_alg.c (afalg_buffer, afalg_stream): Rewrite to avoid
        gotos, as they were a source of unreliability and made the code a
index 64bde8d74e8253f7500e8ece1d1e2c75183acf27..cfc31529afbc70404f9db55eff9495150b1e2f54 100644 (file)
@@ -79,14 +79,14 @@ afalg_buffer (const char *buffer, size_t len, const char *alg,
       ssize_t size = (len > BLOCKSIZE ? BLOCKSIZE : len);
       if (send (ofd, buffer, size, MSG_MORE) != size)
         {
-          result = -EIO;
+          result = -EAFNOSUPPORT;
           break;
         }
       buffer += size;
       len -= size;
       if (len == 0)
         {
-          result = read (ofd, resblock, hashlen) == hashlen ? -EIO: 0;
+          result = read (ofd, resblock, hashlen) == hashlen ? -EAFNOSUPPORT: 0;
           break;
         }
     }
@@ -116,22 +116,14 @@ afalg_stream (FILE *stream, const char *alg,
          Note: fflush on an input stream after ungetc does not work as expected
          on some platforms.  Therefore this situation is not supported here.  */
       if (fflush (stream))
-        {
-#if defined _WIN32 && ! defined __CYGWIN__
-          result = -EIO;
-#else
-          result = -errno;
-#endif
-        }
+        result = -EIO;
       else
         {
           off_t nbytes = st.st_size - lseek (fd, 0, SEEK_CUR);
           /* On Linux < 4.9, the value for an empty stream is wrong (all 0).
              See <https://patchwork.kernel.org/patch/9308641/>.  */
-          if (nbytes <= 0)
+          if (nbytes <= 0 || sendfile (ofd, fd, NULL, nbytes) != nbytes)
             result = -EAFNOSUPPORT;
-          else if (sendfile (ofd, fd, NULL, nbytes) != nbytes)
-            result = -EIO;
         }
     }
   else