diff options
| author | ZyX <kp-pav@yandex.ru> | 2017-11-30 02:02:55 +0300 |
|---|---|---|
| committer | ZyX <kp-pav@yandex.ru> | 2017-11-30 02:02:55 +0300 |
| commit | b588ccddd7f5998ce7d9780463480ca844963859 (patch) | |
| tree | 78f1e0f58209385aa63e0e25e071a5893635790d /src/nvim/fileio.c | |
| parent | de45ec0146486c49719ff6f6dcceb4914b471c7a (diff) | |
| parent | 4618c9c43b2fe052332329b347ac10b4b1db94b5 (diff) | |
| download | rneovim-b588ccddd7f5998ce7d9780463480ca844963859.tar.gz rneovim-b588ccddd7f5998ce7d9780463480ca844963859.tar.bz2 rneovim-b588ccddd7f5998ce7d9780463480ca844963859.zip | |
Merge branch 'master' into expression-parser
Diffstat (limited to 'src/nvim/fileio.c')
| -rw-r--r-- | src/nvim/fileio.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index ae6c3f96e3..1f4cd22754 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -4443,22 +4443,32 @@ char *modname(const char *fname, const char *ext, bool prepend_dot) /// @return true for end-of-file. bool vim_fgets(char_u *buf, int size, FILE *fp) FUNC_ATTR_NONNULL_ALL { - char *eof; -#define FGETS_SIZE 200 - char tbuf[FGETS_SIZE]; + char *retval; + assert(size > 0); buf[size - 2] = NUL; - eof = fgets((char *)buf, size, fp); + + do { + errno = 0; + retval = fgets((char *)buf, size, fp); + } while (retval == NULL && errno == EINTR); + if (buf[size - 2] != NUL && buf[size - 2] != '\n') { - buf[size - 1] = NUL; /* Truncate the line */ + char tbuf[200]; - /* Now throw away the rest of the line: */ + buf[size - 1] = NUL; // Truncate the line. + + // Now throw away the rest of the line: do { - tbuf[FGETS_SIZE - 2] = NUL; - ignoredp = fgets((char *)tbuf, FGETS_SIZE, fp); - } while (tbuf[FGETS_SIZE - 2] != NUL && tbuf[FGETS_SIZE - 2] != '\n'); + tbuf[sizeof(tbuf) - 2] = NUL; + errno = 0; + retval = fgets((char *)tbuf, sizeof(tbuf), fp); + if (retval == NULL && errno != EINTR) { + break; + } + } while (tbuf[sizeof(tbuf) - 2] != NUL && tbuf[sizeof(tbuf) - 2] != '\n'); } - return eof == NULL; + return retval ? false : feof(fp); } /// Read 2 bytes from "fd" and turn them into an int, MSB first. |