+/* Set PORT's internal buffer according to READ_SIZE. */
+static void
+cbip_setvbuf (SCM port, long read_size, long write_size)
+{
+ SCM bv;
+ scm_t_port *pt;
+
+ pt = SCM_PTAB_ENTRY (port);
+ bv = SCM_CBIP_BYTEVECTOR (port);
+
+ switch (read_size)
+ {
+ case 0:
+ /* Unbuffered: keep PORT's bytevector as is (it will be used in
+ future 'scm_c_read' calls), but point to the one-byte buffer. */
+ pt->read_buf = &pt->shortbuf;
+ pt->read_buf_size = 1;
+ break;
+
+ case -1:
+ /* Preferred size: keep the current bytevector and use it as the
+ backing store. */
+ pt->read_buf = (unsigned char *) SCM_BYTEVECTOR_CONTENTS (bv);
+ pt->read_buf_size = SCM_BYTEVECTOR_LENGTH (bv);
+ break;
+
+ default:
+ /* Fully buffered: allocate a buffer of READ_SIZE bytes. */
+ bv = scm_c_make_bytevector (read_size);
+ SCM_SET_CBIP_BYTEVECTOR (port, bv);
+ pt->read_buf = (unsigned char *) SCM_BYTEVECTOR_CONTENTS (bv);
+ pt->read_buf_size = read_size;
+ }
+
+ pt->read_pos = pt->read_end = pt->read_buf;
+}
+