/* Return a new port of type PORT_TYPE. */ static inline SCM make_port (scm_t_bits port_type) { SCM port; char *c_buffer; scm_t_port *c_port; c_buffer = scm_gc_calloc (PORT_BUFFER_SIZE, "custom-port-buffer"); port = scm_new_port_table_entry (port_type); /* Associate C_BUFFER with PORT, for test purposes. */ SCM_SETSTREAM (port, (scm_t_bits) c_buffer); /* Use C_BUFFER as PORT's internal buffer. */ c_port = SCM_PTAB_ENTRY (port); c_port->read_pos = c_port->read_buf = (unsigned char *) c_buffer; c_port->read_end = (unsigned char *) c_buffer + PORT_BUFFER_SIZE; c_port->read_buf_size = PORT_BUFFER_SIZE; /* Mark PORT as open and readable. */ SCM_SET_CELL_TYPE (port, port_type | SCM_OPN | SCM_RDNG); return port; }
static SCM ioscm_open_port (scm_t_bits port_type, long mode_bits) { SCM port; #if 0 /* TODO: Guile doesn't export this. What to do? */ scm_i_scm_pthread_mutex_lock (&scm_i_port_table_mutex); #endif port = scm_new_port_table_entry (port_type); SCM_SET_CELL_TYPE (port, port_type | mode_bits); #if 0 /* TODO: Guile doesn't export this. What to do? */ scm_i_pthread_mutex_unlock (&scm_i_port_table_mutex); #endif return port; }
SCM mu_port_make_from_stream (SCM msg, mu_stream_t stream, long mode) { struct mu_port *mp; SCM port; scm_port *pt; mp = scm_gc_malloc (sizeof (struct mu_port), "mu-port"); mp->msg = msg; mp->stream = stream; mp->offset = 0; port = scm_new_port_table_entry (scm_tc16_smuport | mode); pt = SCM_PTAB_ENTRY (port); pt->rw_random = mu_stream_is_seekable (stream); SCM_SETSTREAM (port, mp); mu_port_alloc_buffer (port, 0, 0); /* FIXME: SCM_PTAB_ENTRY (port)->file_name = "name";*/ return port; }