diff options
author | Jim Meyering <jim@meyering.net> | 1994-01-26 18:19:10 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1994-01-26 18:19:10 +0000 |
commit | 5629153f1eadc2b27dd48ff18a194f6819d9d732 (patch) | |
tree | 60428c4cc180a9940e5d85ae62154f60dfde43f1 /src | |
parent | 2b16e3652c9625a41bbe9a1573316a5c1e65141b (diff) | |
download | coreutils-5629153f1eadc2b27dd48ff18a194f6819d9d732.tar.xz |
.
Diffstat (limited to 'src')
-rw-r--r-- | src/cp.c | 13 | ||||
-rw-r--r-- | src/dd.c | 9 | ||||
-rw-r--r-- | src/install.c | 6 | ||||
-rw-r--r-- | src/mv.c | 27 | ||||
-rw-r--r-- | src/touch.c | 6 |
5 files changed, 33 insertions, 28 deletions
@@ -56,6 +56,7 @@ char *dirname (); char *xstrdup (); enum backup_type get_version (); int eaccess_stat (); +int full_write (); static int do_copy (); static int copy (); @@ -1129,7 +1130,6 @@ copy_reg (src_path, dst_path) int dest_desc; int source_desc; int n_read; - int n_written; struct stat sb; char *cp; int *ip; @@ -1197,6 +1197,10 @@ copy_reg (src_path, dst_path) n_read = read (source_desc, buf, buf_size); if (n_read < 0) { +#ifdef EINTR + if (errno == EINTR) + continue; +#endif error (0, errno, "%s", src_path); return_val = -1; goto ret; @@ -1243,8 +1247,7 @@ copy_reg (src_path, dst_path) } if (ip == 0) { - n_written = write (dest_desc, buf, n_read); - if (n_written < n_read) + if (full_write (dest_desc, buf, n_read) < 0) { error (0, errno, "%s", dst_path); return_val = -1; @@ -1262,12 +1265,12 @@ copy_reg (src_path, dst_path) { #ifdef HAVE_FTRUNCATE /* Write a null character and truncate it again. */ - if (write (dest_desc, "", 1) != 1 + if (full_write (dest_desc, "", 1) < 0 || ftruncate (dest_desc, n_read_total) < 0) #else /* Seek backwards one character and write a null. */ if (lseek (dest_desc, (off_t) -1, SEEK_CUR) < 0L - || write (dest_desc, "", 1) != 1) + || full_write (dest_desc, "", 1) < 0) #endif { error (0, errno, "%s", dst_path); @@ -110,6 +110,7 @@ char *xmalloc (); void error (); +int safe_read (); static RETSIGTYPE interrupt_handler (); static int bit_count (); @@ -446,7 +447,11 @@ skip (fdesc, file, records, blocksize, buf) { while (records-- > 0) { - if (read (fdesc, buf, blocksize) < 0) + if (read (fdesc, buf, blocksize) < 0 +#ifdef EINTR + && errno != EINTR +#endif + ) { error (0, errno, "%s", file); quit (1); @@ -563,7 +568,7 @@ copy () if ((conversions_mask & C_SYNC) && (conversions_mask & C_NOERROR)) bzero (ibuf, input_blocksize); - nread = read (input_fd, ibuf, input_blocksize); + nread = safe_read (input_fd, ibuf, input_blocksize); if (nread == 0) break; /* EOF. */ diff --git a/src/install.c b/src/install.c index 7c6a5d2f7..77617b02a 100644 --- a/src/install.c +++ b/src/install.c @@ -105,6 +105,8 @@ char *basename (); char *stpcpy (); char *xmalloc (); void error (); +int safe_read (); +int full_write (); int make_path (); int isdir (); @@ -374,8 +376,8 @@ copy_file (from, to, to_created) return 1; } - while ((bytes = read (fromfd, buffer, READ_SIZE)) > 0) - if (write (tofd, buffer, bytes) != bytes) + while ((bytes = safe_read (fromfd, buffer, READ_SIZE)) > 0) + if (full_write (tofd, buffer, bytes) < 0) { error (0, errno, "%s", to); goto copy_error; @@ -68,6 +68,8 @@ enum backup_type get_version (); int isdir (); int yesno (); void error (); +int safe_read (); +int full_write (); void strip_trailing_slashes (); int eaccess_stat (); char *stpcpy (); @@ -393,25 +395,16 @@ copy_reg (source, dest) return 1; } - while ((len = read (ifd, buf, sizeof (buf))) > 0) + while ((len = safe_read (ifd, buf, sizeof (buf))) > 0) { - int wrote = 0; - char *bp = buf; - - do + if (full_write (ofd, buf, len) < 0) { - wrote = write (ofd, bp, len); - if (wrote < 0) - { - error (0, errno, "%s", dest); - close (ifd); - close (ofd); - unlink (dest); - return 1; - } - bp += wrote; - len -= wrote; - } while (len > 0); + error (0, errno, "%s", dest); + close (ifd); + close (ofd); + unlink (dest); + return 1; + } } if (len < 0) { diff --git a/src/touch.c b/src/touch.c index b664fae57..33fadc282 100644 --- a/src/touch.c +++ b/src/touch.c @@ -59,6 +59,8 @@ int argmatch (); time_t get_date (); time_t posixtime (); void error (); +int safe_read (); +int full_write (); void invalid_arg (); static int touch (); @@ -365,9 +367,9 @@ utime_now (file, filesize) fd = open (file, O_RDWR, 0666); if (fd < 0 - || read (fd, &c, sizeof (char)) < 0 + || safe_read (fd, &c, sizeof (char)) < 0 || lseek (fd, (off_t) 0, SEEK_SET) < 0 - || write (fd, &c, sizeof (char)) < 0 + || full_write (fd, &c, sizeof (char)) < 0 || ftruncate (fd, filesize) < 0 || close (fd) < 0) status = -1; |