]> git.pld-linux.org Git - packages/vim.git/blob - 7.3.083
- new
[packages/vim.git] / 7.3.083
1 To: vim_dev@googlegroups.com
2 Subject: Patch 7.3.083
3 Fcc: outbox
4 From: Bram Moolenaar <Bram@moolenaar.net>
5 Mime-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8 ------------
9
10 Patch 7.3.083
11 Problem:    When a read() or write() is interrupted by a signal it fails.
12 Solution:   Add read_eintr() and write_eintr().
13 Files:      src/fileio.c, src/proto/fileio.pro, src/memfile.c, src/memline.c,
14             src/os_unix.c, src/undo.c, src/vim.h
15
16
17 *** ../vim-7.3.082/src/fileio.c 2010-08-15 21:57:26.000000000 +0200
18 --- src/fileio.c        2010-12-17 16:04:30.000000000 +0100
19 ***************
20 *** 918,924 ****
21             {
22                 /* Read the first line (and a bit more).  Immediately rewind to
23                  * the start of the file.  If the read() fails "len" is -1. */
24 !               len = vim_read(fd, firstline, 80);
25                 lseek(fd, (off_t)0L, SEEK_SET);
26                 for (p = firstline; p < firstline + len; ++p)
27                     if (*p >= 0x80)
28 --- 918,924 ----
29             {
30                 /* Read the first line (and a bit more).  Immediately rewind to
31                  * the start of the file.  If the read() fails "len" is -1. */
32 !               len = read_eintr(fd, firstline, 80);
33                 lseek(fd, (off_t)0L, SEEK_SET);
34                 for (p = firstline; p < firstline + len; ++p)
35                     if (*p >= 0x80)
36 ***************
37 *** 1373,1379 ****
38                     /*
39                      * Read bytes from the file.
40                      */
41 !                   size = vim_read(fd, ptr, size);
42                 }
43   
44                 if (size <= 0)
45 --- 1373,1379 ----
46                     /*
47                      * Read bytes from the file.
48                      */
49 !                   size = read_eintr(fd, ptr, size);
50                 }
51   
52                 if (size <= 0)
53 ***************
54 *** 4000,4006 ****
55   #ifdef HAS_BW_FLAGS
56                         write_info.bw_flags = FIO_NOCONVERT;
57   #endif
58 !                       while ((write_info.bw_len = vim_read(fd, copybuf,
59                                                                 BUFSIZE)) > 0)
60                         {
61                             if (buf_write_bytes(&write_info) == FAIL)
62 --- 4000,4006 ----
63   #ifdef HAS_BW_FLAGS
64                         write_info.bw_flags = FIO_NOCONVERT;
65   #endif
66 !                       while ((write_info.bw_len = read_eintr(fd, copybuf,
67                                                                 BUFSIZE)) > 0)
68                         {
69                             if (buf_write_bytes(&write_info) == FAIL)
70 ***************
71 *** 4813,4819 ****
72   #ifdef HAS_BW_FLAGS
73                         write_info.bw_flags = FIO_NOCONVERT;
74   #endif
75 !                       while ((write_info.bw_len = vim_read(fd, smallbuf,
76                                                       SMBUFSIZE)) > 0)
77                             if (buf_write_bytes(&write_info) == FAIL)
78                                 break;
79 --- 4813,4819 ----
80   #ifdef HAS_BW_FLAGS
81                         write_info.bw_flags = FIO_NOCONVERT;
82   #endif
83 !                       while ((write_info.bw_len = read_eintr(fd, smallbuf,
84                                                       SMBUFSIZE)) > 0)
85                             if (buf_write_bytes(&write_info) == FAIL)
86                                 break;
87 ***************
88 *** 5330,5336 ****
89   
90   /*
91    * Call write() to write a number of bytes to the file.
92 !  * Also handles encryption and 'encoding' conversion.
93    *
94    * Return FAIL for failure, OK otherwise.
95    */
96 --- 5330,5336 ----
97   
98   /*
99    * Call write() to write a number of bytes to the file.
100 !  * Handles encryption and 'encoding' conversion.
101    *
102    * Return FAIL for failure, OK otherwise.
103    */
104 ***************
105 *** 5702,5717 ****
106         crypt_encode(buf, len, buf);
107   #endif
108   
109 !     /* Repeat the write(), it may be interrupted by a signal. */
110 !     while (len > 0)
111 !     {
112 !       wlen = vim_write(ip->bw_fd, buf, len);
113 !       if (wlen <= 0)              /* error! */
114 !           return FAIL;
115 !       len -= wlen;
116 !       buf += wlen;
117 !     }
118 !     return OK;
119   }
120   
121   #ifdef FEAT_MBYTE
122 --- 5702,5709 ----
123         crypt_encode(buf, len, buf);
124   #endif
125   
126 !     wlen = write_eintr(ip->bw_fd, buf, len);
127 !     return (wlen < len) ? FAIL : OK;
128   }
129   
130   #ifdef FEAT_MBYTE
131 ***************
132 *** 6662,6669 ****
133         return -1;
134       }
135   
136 !     while ((n = vim_read(fd_in, buffer, BUFSIZE)) > 0)
137 !       if (vim_write(fd_out, buffer, n) != n)
138         {
139             errmsg = _("E208: Error writing to \"%s\"");
140             break;
141 --- 6654,6661 ----
142         return -1;
143       }
144   
145 !     while ((n = read_eintr(fd_in, buffer, BUFSIZE)) > 0)
146 !       if (write_eintr(fd_out, buffer, n) != n)
147         {
148             errmsg = _("E208: Error writing to \"%s\"");
149             break;
150 ***************
151 *** 10304,10306 ****
152 --- 10296,10350 ----
153       }
154       return reg_pat;
155   }
156
157 + #if defined(EINTR) || defined(PROTO)
158 + /*
159 +  * Version of read() that retries when interrupted by EINTR (possibly
160 +  * by a SIGWINCH).
161 +  */
162 +     long
163 + read_eintr(fd, buf, bufsize)
164 +     int           fd;
165 +     void    *buf;
166 +     size_t  bufsize;
167 + {
168 +     long ret;
169
170 +     for (;;)
171 +     {
172 +       ret = vim_read(fd, buf, bufsize);
173 +       if (ret >= 0 || errno != EINTR)
174 +           break;
175 +     }
176 +     return ret;
177 + }
178
179 + /*
180 +  * Version of write() that retries when interrupted by EINTR (possibly
181 +  * by a SIGWINCH).
182 +  */
183 +     long
184 + write_eintr(fd, buf, bufsize)
185 +     int           fd;
186 +     void    *buf;
187 +     size_t  bufsize;
188 + {
189 +     long    ret = 0;
190 +     long    wlen;
191
192 +     /* Repeat the write() so long it didn't fail, other than being interrupted
193 +      * by a signal. */
194 +     while (ret < (long)bufsize)
195 +     {
196 +       wlen = vim_write(fd, buf + ret, bufsize - ret);
197 +       if (wlen < 0)
198 +       {
199 +           if (errno != EINTR)
200 +               break;
201 +       }
202 +       else
203 +           ret += wlen;
204 +     }
205 +     return ret;
206 + }
207 + #endif
208 *** ../vim-7.3.082/src/proto/fileio.pro 2010-08-15 21:57:28.000000000 +0200
209 --- src/proto/fileio.pro        2010-12-17 15:01:26.000000000 +0100
210 ***************
211 *** 54,57 ****
212 --- 54,59 ----
213   int match_file_pat __ARGS((char_u *pattern, regprog_T *prog, char_u *fname, char_u *sfname, char_u *tail, int allow_dirs));
214   int match_file_list __ARGS((char_u *list, char_u *sfname, char_u *ffname));
215   char_u *file_pat_to_reg_pat __ARGS((char_u *pat, char_u *pat_end, char *allow_dirs, int no_bslash));
216 + long read_eintr __ARGS((int fd, void *buf, size_t bufsize));
217 + long write_eintr __ARGS((int fd, void *buf, size_t bufsize));
218   /* vim: set ft=c : */
219 *** ../vim-7.3.082/src/memfile.c        2010-08-15 21:57:25.000000000 +0200
220 --- src/memfile.c       2010-12-17 16:02:54.000000000 +0100
221 ***************
222 *** 1049,1055 ****
223         PERROR(_("E294: Seek error in swap file read"));
224         return FAIL;
225       }
226 !     if ((unsigned)vim_read(mfp->mf_fd, hp->bh_data, size) != size)
227       {
228         PERROR(_("E295: Read error in swap file"));
229         return FAIL;
230 --- 1049,1055 ----
231         PERROR(_("E294: Seek error in swap file read"));
232         return FAIL;
233       }
234 !     if ((unsigned)read_eintr(mfp->mf_fd, hp->bh_data, size) != size)
235       {
236         PERROR(_("E295: Read error in swap file"));
237         return FAIL;
238 ***************
239 *** 1168,1174 ****
240       }
241   #endif
242   
243 !     if ((unsigned)vim_write(mfp->mf_fd, data, size) != size)
244         result = FAIL;
245   
246   #ifdef FEAT_CRYPT
247 --- 1168,1174 ----
248       }
249   #endif
250   
251 !     if ((unsigned)write_eintr(mfp->mf_fd, data, size) != size)
252         result = FAIL;
253   
254   #ifdef FEAT_CRYPT
255 *** ../vim-7.3.082/src/memline.c        2010-12-08 13:16:58.000000000 +0100
256 --- src/memline.c       2010-12-17 15:46:49.000000000 +0100
257 ***************
258 *** 2062,2068 ****
259       fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0);
260       if (fd >= 0)
261       {
262 !       if (read(fd, (char *)&b0, sizeof(b0)) == sizeof(b0))
263         {
264             if (STRNCMP(b0.b0_version, "VIM 3.0", 7) == 0)
265             {
266 --- 2062,2068 ----
267       fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0);
268       if (fd >= 0)
269       {
270 !       if (read_eintr(fd, &b0, sizeof(b0)) == sizeof(b0))
271         {
272             if (STRNCMP(b0.b0_version, "VIM 3.0", 7) == 0)
273             {
274 ***************
275 *** 4392,4398 ****
276                 fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0);
277                 if (fd >= 0)
278                 {
279 !                   if (read(fd, (char *)&b0, sizeof(b0)) == sizeof(b0))
280                     {
281                         /*
282                          * If the swapfile has the same directory as the
283 --- 4392,4398 ----
284                 fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0);
285                 if (fd >= 0)
286                 {
287 !                   if (read_eintr(fd, &b0, sizeof(b0)) == sizeof(b0))
288                     {
289                         /*
290                          * If the swapfile has the same directory as the
291 *** ../vim-7.3.082/src/os_unix.c        2010-10-20 19:17:43.000000000 +0200
292 --- src/os_unix.c       2010-12-17 16:17:43.000000000 +0100
293 ***************
294 *** 4454,4460 ****
295                     ++noread_cnt;
296                     while (RealWaitForChar(fromshell_fd, 10L, NULL))
297                     {
298 !                       len = read(fromshell_fd, (char *)buffer
299   # ifdef FEAT_MBYTE
300                                 + buffer_off, (size_t)(BUFLEN - buffer_off)
301   # else
302 --- 4454,4460 ----
303                     ++noread_cnt;
304                     while (RealWaitForChar(fromshell_fd, 10L, NULL))
305                     {
306 !                       len = read_eintr(fromshell_fd, buffer
307   # ifdef FEAT_MBYTE
308                                 + buffer_off, (size_t)(BUFLEN - buffer_off)
309   # else
310 *** ../vim-7.3.082/src/undo.c   2010-11-03 19:32:36.000000000 +0100
311 --- src/undo.c  2010-12-17 15:39:24.000000000 +0100
312 ***************
313 *** 1386,1392 ****
314                 char_u  mbuf[UF_START_MAGIC_LEN];
315                 int     len;
316   
317 !               len = vim_read(fd, mbuf, UF_START_MAGIC_LEN);
318                 close(fd);
319                 if (len < UF_START_MAGIC_LEN
320                       || memcmp(mbuf, UF_START_MAGIC, UF_START_MAGIC_LEN) != 0)
321 --- 1386,1392 ----
322                 char_u  mbuf[UF_START_MAGIC_LEN];
323                 int     len;
324   
325 !               len = read_eintr(fd, mbuf, UF_START_MAGIC_LEN);
326                 close(fd);
327                 if (len < UF_START_MAGIC_LEN
328                       || memcmp(mbuf, UF_START_MAGIC, UF_START_MAGIC_LEN) != 0)
329 *** ../vim-7.3.082/src/vim.h    2010-12-02 16:01:23.000000000 +0100
330 --- src/vim.h   2010-12-17 14:55:04.000000000 +0100
331 ***************
332 *** 1642,1647 ****
333 --- 1642,1652 ----
334   # define USE_INPUT_BUF
335   #endif
336   
337 + #ifndef EINTR
338 + # define read_eintr(fd, buf, count) vim_read((fd), (buf), (count))
339 + # define write_eintr(fd, buf, count) vim_write((fd), (buf), (count))
340 + #endif
341
342   #ifdef MSWIN
343   /* On MS-Windows the third argument isn't size_t.  This matters for Win64,
344    * where sizeof(size_t)==8, not 4 */
345 *** ../vim-7.3.082/src/version.c        2010-12-17 12:19:14.000000000 +0100
346 --- src/version.c       2010-12-17 16:10:58.000000000 +0100
347 ***************
348 *** 716,717 ****
349 --- 716,719 ----
350   {   /* Add new patch number below this line */
351 + /**/
352 +     83,
353   /**/
354
355 -- 
356 How To Keep A Healthy Level Of Insanity:
357 9. As often as possible, skip rather than walk.
358
359  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
360 ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
361 \\\  an exciting new programming language -- http://www.Zimbu.org        ///
362  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
This page took 0.071954 seconds and 3 git commands to generate.