]> granicus.if.org Git - vim/commitdiff
updated for version 7.3.083 v7.3.083
authorBram Moolenaar <Bram@vim.org>
Fri, 17 Dec 2010 15:27:16 +0000 (16:27 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 17 Dec 2010 15:27:16 +0000 (16:27 +0100)
Problem:    When a read() or write() is interrupted by a signal it fails.
Solution:   Add read_eintr() and write_eintr().

src/fileio.c
src/memfile.c
src/memline.c
src/os_unix.c
src/proto/fileio.pro
src/undo.c
src/version.c
src/vim.h

index b6127d9dd4093a7b0f2dc16069c883296697558f..2828aa72af4a24dddc61a0456e7bdbb6e231c1cb 100644 (file)
@@ -918,7 +918,7 @@ readfile(fname, sfname, from, lines_to_skip, lines_to_read, eap, flags)
            {
                /* Read the first line (and a bit more).  Immediately rewind to
                 * the start of the file.  If the read() fails "len" is -1. */
-               len = vim_read(fd, firstline, 80);
+               len = read_eintr(fd, firstline, 80);
                lseek(fd, (off_t)0L, SEEK_SET);
                for (p = firstline; p < firstline + len; ++p)
                    if (*p >= 0x80)
@@ -1373,7 +1373,7 @@ retry:
                    /*
                     * Read bytes from the file.
                     */
-                   size = vim_read(fd, ptr, size);
+                   size = read_eintr(fd, ptr, size);
                }
 
                if (size <= 0)
@@ -4000,7 +4000,7 @@ buf_write(buf, fname, sfname, start, end, eap, append, forceit,
 #ifdef HAS_BW_FLAGS
                        write_info.bw_flags = FIO_NOCONVERT;
 #endif
-                       while ((write_info.bw_len = vim_read(fd, copybuf,
+                       while ((write_info.bw_len = read_eintr(fd, copybuf,
                                                                BUFSIZE)) > 0)
                        {
                            if (buf_write_bytes(&write_info) == FAIL)
@@ -4813,7 +4813,7 @@ restore_backup:
 #ifdef HAS_BW_FLAGS
                        write_info.bw_flags = FIO_NOCONVERT;
 #endif
-                       while ((write_info.bw_len = vim_read(fd, smallbuf,
+                       while ((write_info.bw_len = read_eintr(fd, smallbuf,
                                                      SMBUFSIZE)) > 0)
                            if (buf_write_bytes(&write_info) == FAIL)
                                break;
@@ -5330,7 +5330,7 @@ time_differs(t1, t2)
 
 /*
  * Call write() to write a number of bytes to the file.
- * Also handles encryption and 'encoding' conversion.
+ * Handles encryption and 'encoding' conversion.
  *
  * Return FAIL for failure, OK otherwise.
  */
@@ -5702,16 +5702,8 @@ buf_write_bytes(ip)
        crypt_encode(buf, len, buf);
 #endif
 
-    /* Repeat the write(), it may be interrupted by a signal. */
-    while (len > 0)
-    {
-       wlen = vim_write(ip->bw_fd, buf, len);
-       if (wlen <= 0)              /* error! */
-           return FAIL;
-       len -= wlen;
-       buf += wlen;
-    }
-    return OK;
+    wlen = write_eintr(ip->bw_fd, buf, len);
+    return (wlen < len) ? FAIL : OK;
 }
 
 #ifdef FEAT_MBYTE
@@ -6662,8 +6654,8 @@ vim_rename(from, to)
        return -1;
     }
 
-    while ((n = vim_read(fd_in, buffer, BUFSIZE)) > 0)
-       if (vim_write(fd_out, buffer, n) != n)
+    while ((n = read_eintr(fd_in, buffer, BUFSIZE)) > 0)
+       if (write_eintr(fd_out, buffer, n) != n)
        {
            errmsg = _("E208: Error writing to \"%s\"");
            break;
@@ -10304,3 +10296,55 @@ file_pat_to_reg_pat(pat, pat_end, allow_dirs, no_bslash)
     }
     return reg_pat;
 }
+
+#if defined(EINTR) || defined(PROTO)
+/*
+ * Version of read() that retries when interrupted by EINTR (possibly
+ * by a SIGWINCH).
+ */
+    long
+read_eintr(fd, buf, bufsize)
+    int            fd;
+    void    *buf;
+    size_t  bufsize;
+{
+    long ret;
+
+    for (;;)
+    {
+       ret = vim_read(fd, buf, bufsize);
+       if (ret >= 0 || errno != EINTR)
+           break;
+    }
+    return ret;
+}
+
+/*
+ * Version of write() that retries when interrupted by EINTR (possibly
+ * by a SIGWINCH).
+ */
+    long
+write_eintr(fd, buf, bufsize)
+    int            fd;
+    void    *buf;
+    size_t  bufsize;
+{
+    long    ret = 0;
+    long    wlen;
+
+    /* Repeat the write() so long it didn't fail, other than being interrupted
+     * by a signal. */
+    while (ret < (long)bufsize)
+    {
+       wlen = vim_write(fd, buf + ret, bufsize - ret);
+       if (wlen < 0)
+       {
+           if (errno != EINTR)
+               break;
+       }
+       else
+           ret += wlen;
+    }
+    return ret;
+}
+#endif
index c6f5fdf8d0bbef185e379771c5481090f20447b8..e9fe314e427d471be92d1b10dbaf252e2757e454 100644 (file)
@@ -1049,7 +1049,7 @@ mf_read(mfp, hp)
        PERROR(_("E294: Seek error in swap file read"));
        return FAIL;
     }
-    if ((unsigned)vim_read(mfp->mf_fd, hp->bh_data, size) != size)
+    if ((unsigned)read_eintr(mfp->mf_fd, hp->bh_data, size) != size)
     {
        PERROR(_("E295: Read error in swap file"));
        return FAIL;
@@ -1168,7 +1168,7 @@ mf_write_block(mfp, hp, offset, size)
     }
 #endif
 
-    if ((unsigned)vim_write(mfp->mf_fd, data, size) != size)
+    if ((unsigned)write_eintr(mfp->mf_fd, data, size) != size)
        result = FAIL;
 
 #ifdef FEAT_CRYPT
index e4e5bad35c60857422f398fc274a25af472503a3..7393324abe7a65100f74980e0cfe74c59d03f632 100644 (file)
@@ -2062,7 +2062,7 @@ swapfile_info(fname)
     fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0);
     if (fd >= 0)
     {
-       if (read(fd, (char *)&b0, sizeof(b0)) == sizeof(b0))
+       if (read_eintr(fd, &b0, sizeof(b0)) == sizeof(b0))
        {
            if (STRNCMP(b0.b0_version, "VIM 3.0", 7) == 0)
            {
@@ -4392,7 +4392,7 @@ findswapname(buf, dirp, old_fname)
                fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0);
                if (fd >= 0)
                {
-                   if (read(fd, (char *)&b0, sizeof(b0)) == sizeof(b0))
+                   if (read_eintr(fd, &b0, sizeof(b0)) == sizeof(b0))
                    {
                        /*
                         * If the swapfile has the same directory as the
index 9fcebd6a37ef548e0328441d53dbeb19dfa9985c..ba86dbf8507b1757388a31875198aa3e00d329b5 100644 (file)
@@ -4454,7 +4454,7 @@ mch_call_shell(cmd, options)
                    ++noread_cnt;
                    while (RealWaitForChar(fromshell_fd, 10L, NULL))
                    {
-                       len = read(fromshell_fd, (char *)buffer
+                       len = read_eintr(fromshell_fd, buffer
 # ifdef FEAT_MBYTE
                                + buffer_off, (size_t)(BUFLEN - buffer_off)
 # else
index 88d3c27ea1236aa326ddffe83c795d0081367484..cb4012f8eb6c003512d0216b5d3dbc5d14265829 100644 (file)
@@ -54,4 +54,6 @@ int au_exists __ARGS((char_u *arg));
 int match_file_pat __ARGS((char_u *pattern, regprog_T *prog, char_u *fname, char_u *sfname, char_u *tail, int allow_dirs));
 int match_file_list __ARGS((char_u *list, char_u *sfname, char_u *ffname));
 char_u *file_pat_to_reg_pat __ARGS((char_u *pat, char_u *pat_end, char *allow_dirs, int no_bslash));
+long read_eintr __ARGS((int fd, void *buf, size_t bufsize));
+long write_eintr __ARGS((int fd, void *buf, size_t bufsize));
 /* vim: set ft=c : */
index 8fb46e4b7979d8ea5014f0b0413ded3710b49153..bcf9463eb4a5e659ee2b3f46f318ce6b9c27860d 100644 (file)
@@ -1386,7 +1386,7 @@ u_write_undo(name, forceit, buf, hash)
                char_u  mbuf[UF_START_MAGIC_LEN];
                int     len;
 
-               len = vim_read(fd, mbuf, UF_START_MAGIC_LEN);
+               len = read_eintr(fd, mbuf, UF_START_MAGIC_LEN);
                close(fd);
                if (len < UF_START_MAGIC_LEN
                      || memcmp(mbuf, UF_START_MAGIC, UF_START_MAGIC_LEN) != 0)
index e3cb9e505354782578047a2818beaa1df6f0054b..346d29100c647ebfd95f7a6977b82f8ac6a3d4ea 100644 (file)
@@ -714,6 +714,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    83,
 /**/
     82,
 /**/
index c799cce9c452ebccbe89a09022e44fa6ac9d41d0..60e91c752c720b7e5268b40966ea101e1bbe7116 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -1642,6 +1642,11 @@ int vim_memcmp __ARGS((void *, void *, size_t));
 # define USE_INPUT_BUF
 #endif
 
+#ifndef EINTR
+# define read_eintr(fd, buf, count) vim_read((fd), (buf), (count))
+# define write_eintr(fd, buf, count) vim_write((fd), (buf), (count))
+#endif
+
 #ifdef MSWIN
 /* On MS-Windows the third argument isn't size_t.  This matters for Win64,
  * where sizeof(size_t)==8, not 4 */