Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

%read in chunks for lseek()able files. #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ AC_PROG_GCC_TRADITIONAL
AC_FUNC_MMAP

AC_FUNC_WAIT3
AC_CHECK_FUNCS(strerror strtol lstat setrlimit sigrelse sighold sigaction \
sysconf setsid sigsetjmp)
AC_CHECK_FUNCS(strerror strtol lseek lstat setrlimit sigrelse sighold \
sigaction sysconf setsid sigsetjmp)

AC_CACHE_CHECK(for an abused getenv, es_cv_abused_getenv,
AC_RUN_IFELSE([AC_LANG_SOURCE([[
Expand Down
25 changes: 23 additions & 2 deletions prim-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,29 @@ PRIM(read) {
freebuffer(buffer);
buffer = openbuffer(0);

while ((c = read1(fd)) != EOF && c != '\n')
buffer = bufputc(buffer, c);
#if HAVE_LSEEK
if (lseek(fd, 0, SEEK_CUR) < 0) {
#endif
while ((c = read1(fd)) != EOF && c != '\n')
buffer = bufputc(buffer, c);
#if HAVE_LSEEK
} else {
int n;
char *p;
char s[BUFSIZE];
c = EOF;
while ((n = eread(fd, s, BUFSIZE)) > 0) {
c = 0;
if ((p = strchr(s, '\n')) == NULL)
buffer = bufncat(buffer, s, n);
else {
buffer = bufncat(buffer, s, (p - s));
lseek(fd, 1 + ((p - s) - n), SEEK_CUR);
break;
}
}
}
#endif

if (c == EOF && buffer->current == 0) {
freebuffer(buffer);
Expand Down