long
scm_mode_bits (char *modes)
{
- return scm_i_mode_bits (scm_from_locale_string (modes));
+ /* Valid characters are rw+a0l. So, use latin1. */
+ return scm_i_mode_bits (scm_from_latin1_string (modes));
}
long
|| !strcmp (encoding, "ISO-8859-1"))
scm_fluid_set_x (SCM_VARIABLE_REF (default_port_encoding_var), SCM_BOOL_F);
else
- scm_fluid_set_x (SCM_VARIABLE_REF (default_port_encoding_var),
- scm_from_locale_string (encoding));
+ {
+ SCM str;
+ size_t i;
+
+ str = scm_from_latin1_string (encoding);
+
+ /* Restrict to ASCII. */
+ for (i = 0; encoding[i]; i++)
+ if (encoding[i] > 127)
+ scm_misc_error ("scm_i_set_default_port_encoding",
+ "invalid character encoding ~s", scm_list_1 (str));
+
+ scm_fluid_set_x (SCM_VARIABLE_REF (default_port_encoding_var), str);
+ }
}
/* Return the name of the default encoding for newly created ports; a
{
scm_t_iconv_descriptors *id;
iconv_t input_cd, output_cd;
+ size_t i;
input_cd = (iconv_t) -1;
output_cd = (iconv_t) -1;
+ for (i = 0; encoding[i]; i++)
+ if (encoding[i] > 127)
+ goto invalid_encoding;
+
if (reading)
{
/* Open an input iconv conversion descriptor, from ENCODING
invalid_encoding:
{
SCM err;
- err = scm_from_locale_string (encoding);
+ err = scm_from_latin1_string (encoding);
scm_misc_error ("open_iconv_descriptors",
"invalid or unknown character encoding ~s",
scm_list_1 (err));
return pt->iconv_descriptors;
}
+/* The name of the encoding is itself encoded in ASCII. */
void
scm_i_set_port_encoding_x (SCM port, const char *encoding)
{
pt = SCM_PTAB_ENTRY (port);
enc = pt->encoding;
if (enc)
- return scm_from_locale_string (pt->encoding);
+ return scm_from_latin1_string (pt->encoding);
else
return SCM_BOOL_F;
}
SCM_VALIDATE_PORT (1, port);
SCM_VALIDATE_STRING (2, enc);
- enc_str = scm_to_locale_string (enc);
+ enc_str = scm_to_latin1_string (enc);
scm_i_set_port_encoding_x (port, enc_str);
free (enc_str);
}
/* Read an ISO-8859-1 codepoint (a byte) from PORT. On success, return
- *0 and set CODEPOINT to the codepoint that was read, fill BUF with
- *its UTF-8 representation, and set *LEN to the length in bytes.
- *Return `EILSEQ' on error. */
+ 0 and set *CODEPOINT to the codepoint that was read, fill BUF with
+ its UTF-8 representation, and set *LEN to the length in bytes.
+ Return `EILSEQ' on error. */
static int
get_latin1_codepoint (SCM port, scm_t_wchar *codepoint,
char buf[SCM_MBCHAR_BUF_SIZE], size_t *len)
with the byte representation of the codepoint in PORT's encoding, and
set *LEN to the length in bytes of that representation. Return 0 on
success and an errno value on error. */
-static int
+static SCM_C_INLINE int
get_codepoint (SCM port, scm_t_wchar *codepoint,
char buf[SCM_MBCHAR_BUF_SIZE], size_t *len)
{
return ret;
}
-/* 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. */
+/* 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;
}
{
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. */