/* create FPORT buffer with specified sizes (or -1 to use default size or 0 for no buffer. */ static void scm_fport_buffer_add (SCM port, long read_size, int write_size) #define FUNC_NAME "scm_fport_buffer_add" { scm_t_port *pt = SCM_PTAB_ENTRY (port); if (read_size == -1 || write_size == -1) { size_t default_size; #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE struct stat st; scm_t_fport *fp = SCM_FSTREAM (port); default_size = (fstat (fp->fdes, &st) == -1) ? default_buffer_size : st.st_blksize; #else default_size = default_buffer_size; #endif if (read_size == -1) read_size = default_size; if (write_size == -1) write_size = default_size; } if (SCM_INPUT_PORT_P (port) && read_size > 0) { pt->read_buf = scm_gc_malloc_pointerless (read_size, "port buffer"); pt->read_pos = pt->read_end = pt->read_buf; pt->read_buf_size = read_size; } else { pt->read_pos = pt->read_buf = pt->read_end = &pt->shortbuf; pt->read_buf_size = 1; } if (SCM_OUTPUT_PORT_P (port) && write_size > 0) { pt->write_buf = scm_gc_malloc_pointerless (write_size, "port buffer"); pt->write_pos = pt->write_buf; pt->write_buf_size = write_size; } else { pt->write_buf = pt->write_pos = &pt->shortbuf; pt->write_buf_size = 1; } pt->write_end = pt->write_buf + pt->write_buf_size; if (read_size > 0 || write_size > 0) SCM_SET_CELL_WORD_0 (port, SCM_CELL_WORD_0 (port) & ~SCM_BUF0); else SCM_SET_CELL_WORD_0 (port, SCM_CELL_WORD_0 (port) | SCM_BUF0); }
static void mu_port_alloc_buffer (SCM port, size_t read_size, size_t write_size) { scm_port *pt = SCM_PTAB_ENTRY (port); static char *s_mu_port_alloc_buffer = "mu_port_alloc_buffer"; if (!read_size) read_size = DEFAULT_BUF_SIZE; if (!write_size) write_size = DEFAULT_BUF_SIZE; if (SCM_INPUT_PORT_P (port)) { pt->read_buf = malloc (read_size); if (pt->read_buf == NULL) scm_memory_error (s_mu_port_alloc_buffer); pt->read_pos = pt->read_end = pt->read_buf; pt->read_buf_size = read_size; } else { pt->read_pos = pt->read_buf = pt->read_end = &pt->shortbuf; pt->read_buf_size = 1; } if (SCM_OUTPUT_PORT_P (port)) { pt->write_buf = malloc (write_size); if (pt->write_buf == NULL) scm_memory_error (s_mu_port_alloc_buffer); pt->write_pos = pt->write_buf; pt->write_buf_size = write_size; pt->write_end = pt->write_buf + pt->write_buf_size; } else { pt->write_buf = pt->write_pos = &pt->shortbuf; pt->write_buf_size = 1; } SCM_SET_CELL_WORD_0 (port, SCM_CELL_WORD_0 (port) & ~SCM_BUF0); }