From: Paul Eggert Date: Wed, 9 May 2018 19:04:37 +0000 (-0700) Subject: af_alg: distiguish I/O errors better X-Git-Tag: v1.0~5630 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=a03d9294699894f9a0c1406458917eebfae533e8;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 9c40bd672a..3a9dc63ec4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2018-05-09 Paul Eggert + 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 diff --git a/lib/af_alg.c b/lib/af_alg.c index 64bde8d74e..cfc31529af 100644 --- a/lib/af_alg.c +++ b/lib/af_alg.c @@ -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 . */ - 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