]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix build failure with -Wunreachable-code compile option; use a for loop statement...
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 25 Feb 2012 11:51:24 +0000 (20:51 +0900)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sun, 26 Feb 2012 07:01:31 +0000 (16:01 +0900)
libarchive/archive_write_add_filter_program.c

index 3dcc9df7bcca7b30d09208735f4bd8d244539f75..d7d38f7072daf8c7078d24aa02967c8d61e9de7b 100644 (file)
@@ -171,60 +171,62 @@ child_write(struct archive_write_filter *f, const char *buf, size_t buf_len)
        if (buf_len == 0)
                return (-1);
 
-restart_write:
-       do {
-               ret = write(data->child_stdin, buf, buf_len);
-       } while (ret == -1 && errno == EINTR);
-
-       if (ret > 0)
-               return (ret);
-       if (ret == 0) {
-               close(data->child_stdin);
-               data->child_stdin = -1;
-               fcntl(data->child_stdout, F_SETFL, 0);
-               return (0);
-       }
-       if (ret == -1 && errno != EAGAIN)
-               return (-1);
-
-       if (data->child_stdout == -1) {
-               fcntl(data->child_stdin, F_SETFL, 0);
-               __archive_check_child(data->child_stdin, data->child_stdout);
-               goto restart_write;
-       }
+       for (;;) {
+               do {
+                       ret = write(data->child_stdin, buf, buf_len);
+               } while (ret == -1 && errno == EINTR);
+
+               if (ret > 0)
+                       return (ret);
+               if (ret == 0) {
+                       close(data->child_stdin);
+                       data->child_stdin = -1;
+                       fcntl(data->child_stdout, F_SETFL, 0);
+                       return (0);
+               }
+               if (ret == -1 && errno != EAGAIN)
+                       return (-1);
+
+               if (data->child_stdout == -1) {
+                       fcntl(data->child_stdin, F_SETFL, 0);
+                       __archive_check_child(data->child_stdin,
+                               data->child_stdout);
+                       continue;
+               }
 
-       do {
-               ret = read(data->child_stdout,
-                   data->child_buf + data->child_buf_avail,
-                   data->child_buf_len - data->child_buf_avail);
-       } while (ret == -1 && errno == EINTR);
+               do {
+                       ret = read(data->child_stdout,
+                           data->child_buf + data->child_buf_avail,
+                           data->child_buf_len - data->child_buf_avail);
+               } while (ret == -1 && errno == EINTR);
 
-       if (ret == 0 || (ret == -1 && errno == EPIPE)) {
-               close(data->child_stdout);
-               data->child_stdout = -1;
-               fcntl(data->child_stdin, F_SETFL, 0);
-               goto restart_write;
-       }
-       if (ret == -1 && errno == EAGAIN) {
-               __archive_check_child(data->child_stdin, data->child_stdout);
-               goto restart_write;
-       }
-       if (ret == -1)
-               return (-1);
+               if (ret == 0 || (ret == -1 && errno == EPIPE)) {
+                       close(data->child_stdout);
+                       data->child_stdout = -1;
+                       fcntl(data->child_stdin, F_SETFL, 0);
+                       continue;
+               }
+               if (ret == -1 && errno == EAGAIN) {
+                       __archive_check_child(data->child_stdin,
+                               data->child_stdout);
+                       continue;
+               }
+               if (ret == -1)
+                       return (-1);
 
-       data->child_buf_avail += ret;
+               data->child_buf_avail += ret;
 
-       ret = __archive_write_filter(f->next_filter,
-           data->child_buf, data->child_buf_avail);
-       if (ret <= 0)
-               return (-1);
+               ret = __archive_write_filter(f->next_filter,
+                   data->child_buf, data->child_buf_avail);
+               if (ret <= 0)
+                       return (-1);
 
-       if ((size_t)ret < data->child_buf_avail) {
-               memmove(data->child_buf, data->child_buf + ret,
-                   data->child_buf_avail - ret);
+               if ((size_t)ret < data->child_buf_avail) {
+                       memmove(data->child_buf, data->child_buf + ret,
+                           data->child_buf_avail - ret);
+               }
+               data->child_buf_avail -= ret;
        }
-       data->child_buf_avail -= ret;
-       goto restart_write;
 }
 
 /*