mirror of
https://github.com/python/cpython.git
synced 2025-12-08 10:21:13 +00:00
Of course, I shouldn't have used lseek() to find out the file's
position in new_buffersize(); the correct function to use is ftell(). Thanks to Ben Jackson.
This commit is contained in:
parent
d65911b3f3
commit
dcb5e7f389
1 changed files with 3 additions and 6 deletions
|
|
@ -406,17 +406,14 @@ new_buffersize(f, currentsize)
|
||||||
size_t currentsize;
|
size_t currentsize;
|
||||||
{
|
{
|
||||||
#ifdef HAVE_FSTAT
|
#ifdef HAVE_FSTAT
|
||||||
#ifndef SEEK_CUR
|
|
||||||
#define SEEK_CUR 1
|
|
||||||
#endif
|
|
||||||
long pos, end;
|
long pos, end;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (fstat(fileno(f->f_fp), &st) == 0) {
|
if (fstat(fileno(f->f_fp), &st) == 0) {
|
||||||
end = st.st_size;
|
end = st.st_size;
|
||||||
pos = lseek(fileno(f->f_fp), 0L, SEEK_CUR);
|
pos = ftell(f->f_fp);
|
||||||
if (end > pos && pos >= 0)
|
if (end > pos && pos >= 0)
|
||||||
return end - pos + BUFSIZ;
|
return end - pos + 1;
|
||||||
/* Add BUFSIZ to allow for stdio buffered data */
|
/* Add 1 so if the file were to grow we'd notice. */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (currentsize > SMALLCHUNK) {
|
if (currentsize > SMALLCHUNK) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue