]> mj.ucw.cz Git - libucw.git/commitdiff
io-careful: Do not fail if a system call is interrupted by a signal
authorJan Filip Chadima <jfch@jagda.eu>
Tue, 25 Feb 2020 15:15:42 +0000 (16:15 +0100)
committerMartin Mares <mj@ucw.cz>
Wed, 26 Feb 2020 17:59:13 +0000 (18:59 +0100)
ucw/io-careful.c

index a3a8a8064e7ab5cada60fabd988ebad212d51261..b679f49f5bf565c1f08125a881ee1b36dd5dcacd 100644 (file)
@@ -2,6 +2,7 @@
  *     UCW Library -- Careful Read/Write
  *
  *     (c) 2004--2012 Martin Mares <mj@ucw.cz>
+ *     (c) 2020 Jan Filip Chadima <jfch@jagda.eu>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
@@ -25,7 +26,11 @@ careful_read(int fd, void *buf, size_t len)
     {
       ssize_t l = read(fd, pos, len);
       if (l < 0)
-       return -1;
+       {
+         if (errno == EINTR)
+           continue;
+         return -1;
+       }
       if (!l)
        return 0;
       pos += l;
@@ -42,7 +47,11 @@ careful_write(int fd, const void *buf, size_t len)
     {
       ssize_t l = write(fd, pos, len);
       if (l < 0)
-       return -1;
+       {
+         if (errno == EINTR)
+           continue;
+         return -1;
+       }
       if (!l)
        return 0;
       pos += l;