This is the mail archive of the
libc-hacker@sourceware.cygnus.com
mailing list for the glibc project.
A libio patch
- To: drepper@cygnus.com (Ulrich Drepper)
- Subject: A libio patch
- From: hjl@lucon.org (H.J. Lu)
- Date: Sat, 24 Oct 1998 17:50:46 -0700 (PDT)
- Cc: libc-hacker@cygnus.com (GNU C Library)
This is needed by VSX-PCT. It is how TET used by VSX-PCT works.
--
H.J. Lu (hjl@gnu.org)
---
Sat Oct 24 17:49:06 1998 H.J. Lu <hjl@gnu.org>
* libio/fileops.c (_IO_new_file_seekoff): Always resync with
the kernel file offset.
* libio/oldfileops.c (_IO_old_file_seekoff): Likewise.
Index: libio/fileops.c
===================================================================
RCS file: /home/work/cvs/gnu/glibc/libio/fileops.c,v
retrieving revision 1.9
diff -u -r1.9 fileops.c
--- fileops.c 1998/10/15 16:43:28 1.9
+++ fileops.c 1998/10/24 16:06:51
@@ -545,7 +545,7 @@
/* If we are only interested in the current position we've found it now. */
if (mode == 0)
- return offset;
+ goto resync;
/* If destination is within current buffer, optimize: */
if (fp->_offset != _IO_pos_BAD && fp->_IO_read_base != NULL
@@ -567,7 +567,7 @@
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
{
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
- return offset;
+ goto resync;
}
}
#ifdef TODO
@@ -579,7 +579,7 @@
if (ignore (to_skip) != to_skip)
goto dumb;
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
- return offset;
+ goto resync;
}
#endif
}
@@ -590,7 +590,7 @@
_IO_switch_to_backup_area (fp);
gbump (fp->_IO_read_end + rel_offset - fp->_IO_read_ptr);
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
- return offset;
+ goto resync;
}
#endif
}
@@ -646,6 +646,16 @@
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
}
return result;
+
+resync:
+ /* We need to do it since it is possible that the file offset in
+ the kernel may be changed behind our back. It may happen when
+ we fopen a file and then do a fork. One process may access the
+ the file and the kernel file offset will be changed. */
+ if (fp->_offset >= 0)
+ _IO_SYSSEEK (fp, fp->_offset, 0);
+
+ return offset;
}
_IO_ssize_t
Index: libio/oldfileops.c
===================================================================
RCS file: /home/work/cvs/gnu/glibc/libio/oldfileops.c,v
retrieving revision 1.1.1.9
diff -u -r1.1.1.9 oldfileops.c
--- oldfileops.c 1998/08/24 15:35:05 1.1.1.9
+++ oldfileops.c 1998/10/24 16:07:26
@@ -496,6 +496,10 @@
}
/* At this point, dir==_IO_seek_set. */
+ /* If we are only interested in the current position we've found it now. */
+ if (mode == 0)
+ goto resync;
+
/* If destination is within current buffer, optimize: */
if (fp->_old_offset != _IO_pos_BAD && fp->_IO_read_base != NULL
&& !_IO_in_backup (fp))
@@ -514,7 +518,7 @@
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + rel_offset,
fp->_IO_read_end);
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
- return offset;
+ goto resync;
}
#ifdef TODO
/* If we have streammarkers, seek forward by reading ahead. */
@@ -524,7 +528,7 @@
- (fp->_IO_read_ptr - fp->_IO_read_base);
if (ignore (to_skip) != to_skip)
goto dumb;
- return offset;
+ goto resync;
}
#endif
}
@@ -534,7 +538,7 @@
if (!_IO_in_backup (fp))
_IO_switch_to_backup_area (fp);
gbump (fp->_IO_read_end + rel_offset - fp->_IO_read_ptr);
- return offset;
+ goto resync;
}
#endif
}
@@ -590,6 +594,16 @@
_IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base);
}
return result;
+
+resync:
+ /* We need to do it since it is possible that the file offset in
+ the kernel may be changed behind our back. It may happen when
+ we fopen a file and then do a fork. One process may access the
+ the file and the kernel file offset will be changed. */
+ if (fp->_old_offset >= 0)
+ _IO_SYSSEEK (fp, fp->_old_offset, 0);
+
+ return offset;
}
_IO_ssize_t