summaryrefslogtreecommitdiff
path: root/libguile/ports.c
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2012-05-08 12:43:06 +0200
committerLudovic Courtès <ludo@gnu.org>2012-05-08 16:11:13 +0200
commite8b21eecb11d261eeecbc7a14fa7f7c16e819a3d (patch)
treef266f2d12dee54004df1d8f6f0c58aa79788d5a3 /libguile/ports.c
parent0eba699d12f638c624efcdc2b617b0aa9099ee1f (diff)
downloadguile-e8b21eecb11d261eeecbc7a14fa7f7c16e819a3d.tar.gz
Fix `setvbuf' to leave the line/column number unchanged.
* libguile/fports.c (scm_setvbuf): Use `scm_take_from_input_buffers' directly instead of `scm_drain_input'; use `scm_unget_byte' instead of `scm_unread_string' to put the drained input back to PORT. This leaves PORT's line/column numbers unchanged, whereas they'd previously be decreased by the `scm_unread_string' call. * libguile/ports.c (scm_take_from_input_buffers): Update description and variable names to refer to "bytes", not "chars". * test-suite/tests/ports.test ("setvbuf"): New test prefix.
Diffstat (limited to 'libguile/ports.c')
-rw-r--r--libguile/ports.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/libguile/ports.c b/libguile/ports.c
index 2d8b9ed48..3ef92b902 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -289,19 +289,21 @@ SCM_DEFINE (scm_char_ready_p, "char-ready?", 0, 1, 0,
}
#undef FUNC_NAME
-/* move up to read_len chars from port's putback and/or read buffers
- into memory starting at dest. returns the number of chars moved. */
-size_t scm_take_from_input_buffers (SCM port, char *dest, size_t read_len)
+/* Move up to READ_LEN bytes from PORT's putback and/or read buffers
+ into memory starting at DEST. Return the number of bytes moved.
+ PORT's line/column numbers are left unchanged. */
+size_t
+scm_take_from_input_buffers (SCM port, char *dest, size_t read_len)
{
scm_t_port *pt = SCM_PTAB_ENTRY (port);
- size_t chars_read = 0;
+ size_t bytes_read = 0;
size_t from_buf = min (pt->read_end - pt->read_pos, read_len);
if (from_buf > 0)
{
memcpy (dest, pt->read_pos, from_buf);
pt->read_pos += from_buf;
- chars_read += from_buf;
+ bytes_read += from_buf;
read_len -= from_buf;
dest += from_buf;
}
@@ -314,10 +316,11 @@ size_t scm_take_from_input_buffers (SCM port, char *dest, size_t read_len)
{
memcpy (dest, pt->saved_read_pos, from_buf);
pt->saved_read_pos += from_buf;
- chars_read += from_buf;
+ bytes_read += from_buf;
}
}
- return chars_read;
+
+ return bytes_read;
}
/* Clear a port's read buffers, returning the contents. */