char * gdbscm_scm_to_target_string_unsafe (SCM string, size_t *lenp, struct gdbarch *gdbarch) { return scm_to_stringn (string, lenp, target_charset (gdbarch), SCM_FAILED_CONVERSION_ERROR); }
static SCM gdbscm_call_scm_to_stringn (void *datap) { struct scm_to_stringn_data *data = datap; data->result = scm_to_stringn (data->string, data->lenp, data->charset, data->conversion_kind); return SCM_BOOL_F; }
/* Return a new string port with MODES. If STR is #f, a new backing buffer is allocated; otherwise STR must be a string and a copy of it serves as the buffer for the new port. */ SCM scm_mkstrport (SCM pos, SCM str, long modes, const char *caller) { SCM z, buf; scm_t_port *pt; const char *encoding; size_t read_buf_size, str_len, c_pos; char *c_buf; if (!((modes & SCM_WRTNG) || (modes & SCM_RDNG))) scm_misc_error ("scm_mkstrport", "port must read or write", SCM_EOL); encoding = scm_i_default_port_encoding (); if (scm_is_false (str)) { /* Allocate a new buffer to write to. */ str_len = INITIAL_BUFFER_SIZE; buf = scm_c_make_bytevector (str_len); c_buf = (char *) SCM_BYTEVECTOR_CONTENTS (buf); /* Reset `read_buf_size'. It will contain the actual number of bytes written to the port. */ read_buf_size = 0; c_pos = 0; } else { /* STR is a string. */ char *copy; SCM_ASSERT (scm_is_string (str), str, SCM_ARG1, caller); /* Create a copy of STR in ENCODING. */ copy = scm_to_stringn (str, &str_len, encoding, SCM_FAILED_CONVERSION_ERROR); buf = scm_c_make_bytevector (str_len); c_buf = (char *) SCM_BYTEVECTOR_CONTENTS (buf); memcpy (c_buf, copy, str_len); free (copy); c_pos = scm_to_unsigned_integer (pos, 0, str_len); read_buf_size = str_len; } z = scm_c_make_port_with_encoding (scm_tc16_strport, modes, encoding, scm_i_default_port_conversion_handler (), (scm_t_bits)buf); pt = SCM_PTAB_ENTRY (z); pt->write_buf = pt->read_buf = (unsigned char *) c_buf; pt->read_pos = pt->write_pos = pt->read_buf + c_pos; pt->read_buf_size = read_buf_size; pt->write_buf_size = str_len; pt->write_end = pt->read_end = pt->read_buf + pt->read_buf_size; pt->rw_random = 1; return z; }