diff options
author | Michael Gran <spk121@yahoo.com> | 2010-07-16 06:44:59 -0700 |
---|---|---|
committer | Michael Gran <spk121@yahoo.com> | 2010-07-16 06:44:59 -0700 |
commit | e50d921bd87e53df33c04831ecf8b3d100af2b7b (patch) | |
tree | 8b3261059e6ee49f2d5b4e049b33cd9a47be7046 /libguile/rdelim.c | |
parent | daedbca7de1350e85cc059654e204744052575c1 (diff) | |
download | guile-e50d921bd87e53df33c04831ecf8b3d100af2b7b.tar.gz |
read-line should use port's encoding, not locale's encoding
* libguile/rdelim.c (scm_read_line): modified, use port's encoding
* test-suite/test/ports.test: new test
Diffstat (limited to 'libguile/rdelim.c')
-rw-r--r-- | libguile/rdelim.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/libguile/rdelim.c b/libguile/rdelim.c index 1f46e5bf0..1340c629c 100644 --- a/libguile/rdelim.c +++ b/libguile/rdelim.c @@ -205,12 +205,16 @@ SCM_DEFINE (scm_read_line, "%read-line", 0, 1, 0, char *s; size_t slen = 0; SCM line, term; + const char *enc; + scm_t_string_failed_conversion_handler hndl; if (SCM_UNBNDP (port)) port = scm_current_input_port (); SCM_VALIDATE_OPINPORT (1,port); pt = SCM_PTAB_ENTRY (port); + enc = pt->encoding; + hndl = pt->ilseq_handler; if (pt->rw_active == SCM_PORT_WRITE) scm_ptobs[SCM_PTOBNUM (port)].flush (port); @@ -220,19 +224,22 @@ SCM_DEFINE (scm_read_line, "%read-line", 0, 1, 0, term = line = SCM_EOF_VAL; else { - if (s[slen-1] == '\n') + if (s[slen - 1] == '\n') { term = SCM_MAKE_CHAR ('\n'); - s[slen-1] = '\0'; - line = scm_take_locale_stringn (s, slen-1); + s[slen - 1] = '\0'; + + line = scm_from_stringn (s, slen - 1, enc, hndl); + free (s); SCM_INCLINE (port); } else { /* Fix: we should check for eof on the port before assuming this. */ term = SCM_EOF_VAL; - line = scm_take_locale_stringn (s, slen); - SCM_COL (port) += slen; + line = scm_from_stringn (s, slen, enc, hndl); + free (s); + SCM_COL (port) += scm_i_string_length (line); } } |