summaryrefslogtreecommitdiff
path: root/libguile/fports.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2016-04-04 11:28:28 +0200
committerAndy Wingo <wingo@pobox.com>2016-04-04 16:30:57 +0200
commitb77fb752dd7e14876741ecb6360ef0319eae18e0 (patch)
treec8c54b604d9f77f2634b0307bbf52dbccc9af39a /libguile/fports.c
parentb7e49a75a9f0c4f992c212e9f61de164dbaa66ec (diff)
downloadguile-b77fb752dd7e14876741ecb6360ef0319eae18e0.tar.gz
Flush buffered reads / writes before seeking
* libguile/ports.c (scm_seek): Flush before seeking on a buffered port. * libguile/fports.c (fport_seek): * libguile/strports.c (st_seek): Remove code to flush buffers. * test-suite/tests/ports.test: Update test expectations that the putback buffer is flushed on a seek. Previously there was a special case for SEEK_CUR with an offset of 0 to avoid flushing buffers, but that's an arbitrary choice that differs from all other combinations of OFFSET and WHENCE.
Diffstat (limited to 'libguile/fports.c')
-rw-r--r--libguile/fports.c42
1 files changed, 2 insertions, 40 deletions
diff --git a/libguile/fports.c b/libguile/fports.c
index 2b415b9a8..e33bfe58c 100644
--- a/libguile/fports.c
+++ b/libguile/fports.c
@@ -670,50 +670,12 @@ fport_fill_input (SCM port)
static scm_t_off
fport_seek (SCM port, scm_t_off offset, int whence)
{
- scm_t_port *pt = SCM_PTAB_ENTRY (port);
scm_t_fport *fp = SCM_FSTREAM (port);
- off_t_or_off64_t rv;
off_t_or_off64_t result;
- if (pt->rw_active == SCM_PORT_WRITE)
- {
- if (offset != 0 || whence != SEEK_CUR)
- {
- fport_flush (port);
- result = rv = lseek_or_lseek64 (fp->fdes, offset, whence);
- }
- else
- {
- /* read current position without disturbing the buffer. */
- rv = lseek_or_lseek64 (fp->fdes, offset, whence);
- result = rv + (pt->write_pos - pt->write_buf);
- }
- }
- else if (pt->rw_active == SCM_PORT_READ)
- {
- if (offset != 0 || whence != SEEK_CUR)
- {
- /* could expand to avoid a second seek. */
- scm_end_input_unlocked (port);
- result = rv = lseek_or_lseek64 (fp->fdes, offset, whence);
- }
- else
- {
- /* read current position without disturbing the buffer
- (particularly the unread-char buffer). */
- rv = lseek_or_lseek64 (fp->fdes, offset, whence);
- result = rv - (pt->read_end - pt->read_pos);
-
- if (pt->read_buf == pt->putback_buf)
- result -= pt->saved_read_end - pt->saved_read_pos;
- }
- }
- else /* SCM_PORT_NEITHER */
- {
- result = rv = lseek_or_lseek64 (fp->fdes, offset, whence);
- }
+ result = lseek_or_lseek64 (fp->fdes, offset, whence);
- if (rv == -1)
+ if (result == -1)
scm_syserror ("fport_seek");
return result;