mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-24 20:30:28 +02:00
Do not scan for coding declarations in open-file.
* libguile/fports.c (scm_open_file): Do not scan for coding declarations. Replace 'use_encoding' local variable with 'binary'. Update documentation string. * module/ice-9/psyntax.scm (include): Add the same file-encoding logic that's used in compile-file and scm_primitive_load. * module/ice-9/psyntax-pp.scm: Regenerate. * doc/ref/api-io.texi (File Ports): Update docs. * test-suite/tests/ports.test: Change "open-file HONORS file coding declarations" test to "open-file IGNORES file coding declaration". * test-suite/tests/coding.test (scan-coding): Use 'file-encoding' to scan for the encoding, since 'open-input-file' no longer does so.
This commit is contained in:
parent
bc3901092d
commit
9a334eb3ab
6 changed files with 40 additions and 44 deletions
|
@ -349,8 +349,7 @@ SCM_DEFINE (scm_open_file, "open-file", 2, 0, 0,
|
|||
"@item b\n"
|
||||
"Open the underlying file in binary mode, if supported by the system.\n"
|
||||
"Also, open the file using the binary-compatible character encoding\n"
|
||||
"\"ISO-8859-1\", ignoring the port's encoding and the coding declaration\n"
|
||||
"at the top of the input file, if any.\n"
|
||||
"\"ISO-8859-1\", ignoring the default port encoding.\n"
|
||||
"@item +\n"
|
||||
"Open the port for both input and output. E.g., @code{r+}: open\n"
|
||||
"an existing file for both input and output.\n"
|
||||
|
@ -365,11 +364,6 @@ SCM_DEFINE (scm_open_file, "open-file", 2, 0, 0,
|
|||
"Add line-buffering to the port. The port output buffer will be\n"
|
||||
"automatically flushed whenever a newline character is written.\n"
|
||||
"@end table\n"
|
||||
"When the file is opened, this procedure will scan for a coding\n"
|
||||
"declaration@pxref{Character Encoding of Source Files}. If present\n"
|
||||
"will use that encoding for interpreting the file. Otherwise, the\n"
|
||||
"port's encoding will be used.\n"
|
||||
"\n"
|
||||
"In theory we could create read/write ports which were buffered\n"
|
||||
"in one direction only. However this isn't included in the\n"
|
||||
"current interfaces. If a file cannot be opened with the access\n"
|
||||
|
@ -377,7 +371,7 @@ SCM_DEFINE (scm_open_file, "open-file", 2, 0, 0,
|
|||
#define FUNC_NAME s_scm_open_file
|
||||
{
|
||||
SCM port;
|
||||
int fdes, flags = 0, use_encoding = 1;
|
||||
int fdes, flags = 0, binary = 0;
|
||||
unsigned int retries;
|
||||
char *file, *md, *ptr;
|
||||
|
||||
|
@ -412,7 +406,7 @@ SCM_DEFINE (scm_open_file, "open-file", 2, 0, 0,
|
|||
flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
|
||||
break;
|
||||
case 'b':
|
||||
use_encoding = 0;
|
||||
binary = 1;
|
||||
#if defined (O_BINARY)
|
||||
flags |= O_BINARY;
|
||||
#endif
|
||||
|
@ -451,20 +445,8 @@ SCM_DEFINE (scm_open_file, "open-file", 2, 0, 0,
|
|||
port = scm_i_fdes_to_port (fdes, scm_i_mode_bits (mode),
|
||||
fport_canonicalize_filename (filename));
|
||||
|
||||
if (use_encoding)
|
||||
{
|
||||
/* If this file has a coding declaration, use that as the port
|
||||
encoding. */
|
||||
if (SCM_INPUT_PORT_P (port))
|
||||
{
|
||||
char *enc = scm_i_scan_for_encoding (port);
|
||||
if (enc != NULL)
|
||||
scm_i_set_port_encoding_x (port, enc);
|
||||
}
|
||||
}
|
||||
else
|
||||
/* If this is a binary file, use the binary-friendly ISO-8859-1
|
||||
encoding. */
|
||||
if (binary)
|
||||
/* Use the binary-friendly ISO-8859-1 encoding. */
|
||||
scm_i_set_port_encoding_x (port, NULL);
|
||||
|
||||
scm_dynwind_end ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue