diff options
author | Andy Wingo <wingo@pobox.com> | 2017-02-14 21:57:35 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2017-02-14 22:03:21 +0100 |
commit | 69ca2bb2217303b2556b131f3995ca4f6af81234 (patch) | |
tree | a8ef7e23995f35b974db988254aabe5a37c72922 /libguile/read.c | |
parent | 2c02bdda191eecd998c33b00c56752b8ec7378ab (diff) |
Elide syscalls in fdes->port
* libguile/fports.h (scm_t_fport): Add options field.
(SCM_FDES_RANDOM_P): Deprecate.
(scm_i_fdes_to_port): Add options argument.
* libguile/fports.c (scm_i_fdes_to_port): Add options argument. Only
verify FD if SCM_FPORT_OPTION_VERIFY is there.
(scm_fdes_to_port, scm_open_file_with_encoding): Adapt to
scm_i_fdes_to_port changes.
(fport_random_access_p): Don't try to seek if NOT_SEEKABLE option is
set.
* libguile/deprecated.h:
* libguile/deprecated.c (SCM_FDES_RANDOM_P): Deprecate.
* NEWS: Add deprecation.
* libguile/filesys.c:
* libguile/ioext.c:
* libguile/posix.c:
* libguile/read.c:
* libguile/socket.c: Adapt callers.
Diffstat (limited to 'libguile/read.c')
-rw-r--r-- | libguile/read.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/libguile/read.c b/libguile/read.c index 5c436e2b2..085cdb9f1 100644 --- a/libguile/read.c +++ b/libguile/read.c @@ -2105,21 +2105,17 @@ scm_i_scan_for_encoding (SCM port) memcpy (header, scm_port_buffer_take_pointer (buf, cur), bytes_read); header[bytes_read] = '\0'; } - else + else if (pt->rw_random) { - /* Try to read some bytes and then seek back. Not all ports - support seeking back; and indeed some file ports (like - /dev/urandom) will succeed on an lseek (fd, 0, SEEK_CUR)---the - check performed by SCM_FPORT_FDES---but fail to seek - backwards. Hence this block comes second. We prefer to use - the read buffer in-place. */ - if (SCM_FPORTP (port) && !SCM_FDES_RANDOM_P (SCM_FPORT_FDES (port))) - return NULL; - + /* The port is seekable. This is OK but grubbing in the read + buffer is better, so this case is just a fallback. */ bytes_read = scm_c_read (port, header, SCM_ENCODING_SEARCH_SIZE); header[bytes_read] = '\0'; scm_seek (port, scm_from_int (0), scm_from_int (SEEK_SET)); } + else + /* No input available and not seekable; scan fails. */ + return NULL; /* search past "coding[:=]" */ pos = header; |