Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 36f8e2d

Browse files
committed
Use lseek instead of ftell; compensate by adding BUFSIZE
1 parent c6ef204 commit 36f8e2d

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Objects/fileobject.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,17 @@ new_buffersize(f, currentsize)
406406
size_t currentsize;
407407
{
408408
#ifdef HAVE_FSTAT
409+
#ifndef SEEK_CUR
410+
#define SEEK_CUR 1
411+
#endif
409412
long pos, end;
410413
struct stat st;
411414
if (fstat(fileno(f->f_fp), &st) == 0) {
412415
end = st.st_size;
413-
pos = ftell(f->f_fp);
416+
pos = lseek(fileno(f->f_fp), 0L, SEEK_CUR);
414417
if (end > pos && pos >= 0)
415-
return end - pos + 1;
418+
return end - pos + BUFSIZ;
419+
/* Add BUFSIZ to allow for stdio buffered data */
416420
}
417421
#endif
418422
if (currentsize > SMALLCHUNK) {

0 commit comments

Comments
 (0)