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