{
/* 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)
/*
* Read bytes from the file.
*/
- size = vim_read(fd, ptr, size);
+ size = read_eintr(fd, ptr, size);
}
if (size <= 0)
#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)
#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;
/*
* 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.
*/
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
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;
}
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
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)
{
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
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 : */