mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-24 05:20:30 +02:00
names of encodings are ascii
* libguile/ports.c (scm_mode_bits): Parse the mode bits as latin1. (scm_i_set_default_port_encoding, open_iconv_descriptors) (scm_port_encoding, scm_set_port_encoding_x): Restrict the names of encodings to ASCII.
This commit is contained in:
parent
9d381ba478
commit
8ebd06c64b
1 changed files with 25 additions and 6 deletions
|
@ -470,7 +470,8 @@ scm_i_mode_bits_n (SCM modes)
|
||||||
long
|
long
|
||||||
scm_mode_bits (char *modes)
|
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
|
long
|
||||||
|
@ -809,8 +810,20 @@ scm_i_set_default_port_encoding (const char *encoding)
|
||||||
|| !strcmp (encoding, "ISO-8859-1"))
|
|| !strcmp (encoding, "ISO-8859-1"))
|
||||||
scm_fluid_set_x (SCM_VARIABLE_REF (default_port_encoding_var), SCM_BOOL_F);
|
scm_fluid_set_x (SCM_VARIABLE_REF (default_port_encoding_var), SCM_BOOL_F);
|
||||||
else
|
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
|
/* Return the name of the default encoding for newly created ports; a
|
||||||
|
@ -845,10 +858,15 @@ open_iconv_descriptors (const char *encoding, int reading, int writing)
|
||||||
{
|
{
|
||||||
scm_t_iconv_descriptors *id;
|
scm_t_iconv_descriptors *id;
|
||||||
iconv_t input_cd, output_cd;
|
iconv_t input_cd, output_cd;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
input_cd = (iconv_t) -1;
|
input_cd = (iconv_t) -1;
|
||||||
output_cd = (iconv_t) -1;
|
output_cd = (iconv_t) -1;
|
||||||
|
|
||||||
|
for (i = 0; encoding[i]; i++)
|
||||||
|
if (encoding[i] > 127)
|
||||||
|
goto invalid_encoding;
|
||||||
|
|
||||||
if (reading)
|
if (reading)
|
||||||
{
|
{
|
||||||
/* Open an input iconv conversion descriptor, from ENCODING
|
/* Open an input iconv conversion descriptor, from ENCODING
|
||||||
|
@ -893,7 +911,7 @@ open_iconv_descriptors (const char *encoding, int reading, int writing)
|
||||||
invalid_encoding:
|
invalid_encoding:
|
||||||
{
|
{
|
||||||
SCM err;
|
SCM err;
|
||||||
err = scm_from_locale_string (encoding);
|
err = scm_from_latin1_string (encoding);
|
||||||
scm_misc_error ("open_iconv_descriptors",
|
scm_misc_error ("open_iconv_descriptors",
|
||||||
"invalid or unknown character encoding ~s",
|
"invalid or unknown character encoding ~s",
|
||||||
scm_list_1 (err));
|
scm_list_1 (err));
|
||||||
|
@ -933,6 +951,7 @@ scm_i_port_iconv_descriptors (SCM port)
|
||||||
return pt->iconv_descriptors;
|
return pt->iconv_descriptors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The name of the encoding is itself encoded in ASCII. */
|
||||||
void
|
void
|
||||||
scm_i_set_port_encoding_x (SCM port, const char *encoding)
|
scm_i_set_port_encoding_x (SCM port, const char *encoding)
|
||||||
{
|
{
|
||||||
|
@ -984,7 +1003,7 @@ SCM_DEFINE (scm_port_encoding, "port-encoding", 1, 0, 0,
|
||||||
pt = SCM_PTAB_ENTRY (port);
|
pt = SCM_PTAB_ENTRY (port);
|
||||||
enc = pt->encoding;
|
enc = pt->encoding;
|
||||||
if (enc)
|
if (enc)
|
||||||
return scm_from_locale_string (pt->encoding);
|
return scm_from_latin1_string (pt->encoding);
|
||||||
else
|
else
|
||||||
return SCM_BOOL_F;
|
return SCM_BOOL_F;
|
||||||
}
|
}
|
||||||
|
@ -1004,7 +1023,7 @@ SCM_DEFINE (scm_set_port_encoding_x, "set-port-encoding!", 2, 0, 0,
|
||||||
SCM_VALIDATE_PORT (1, port);
|
SCM_VALIDATE_PORT (1, port);
|
||||||
SCM_VALIDATE_STRING (2, enc);
|
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);
|
scm_i_set_port_encoding_x (port, enc_str);
|
||||||
free (enc_str);
|
free (enc_str);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue