/* Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
- * 2004, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
+ * 2004, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
#define FUNC_NAME s_scm_open_file
{
SCM port;
- int fdes, flags = 0, scan_for_encoding = 0, consume_bom = 0, binary = 0;
+ int fdes, flags = 0, use_encoding = 1;
unsigned int retries;
char *file, *md, *ptr;
{
case 'r':
flags |= O_RDONLY;
- consume_bom = 1;
- scan_for_encoding = 1;
break;
case 'w':
flags |= O_WRONLY | O_CREAT | O_TRUNC;
{
case '+':
flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
- consume_bom = 0;
break;
case 'b':
- scan_for_encoding = 0;
- consume_bom = 0;
- binary = 1;
+ use_encoding = 0;
#if defined (O_BINARY)
flags |= O_BINARY;
#endif
port = scm_i_fdes_to_port (fdes, scm_i_mode_bits (mode),
fport_canonicalize_filename (filename));
- if (consume_bom)
- scm_consume_byte_order_mark (port);
-
- if (binary)
+ 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. */
scm_i_set_port_encoding_x (port, NULL);
- else if (scan_for_encoding)
- /* If this is an input port and the file has a coding declaration,
- use that as the port encoding. */
- {
- char *enc = scm_i_scan_for_encoding (port);
- if (enc != NULL)
- scm_i_set_port_encoding_x (port, enc);
- }
scm_dynwind_end ();