Do magic to mix reads and writes on stdio FILE-based ports.
authorJim Blandy <jimb@red-bean.com>
Fri, 9 Oct 1998 12:45:20 +0000 (12:45 +0000)
committerJim Blandy <jimb@red-bean.com>
Fri, 9 Oct 1998 12:45:20 +0000 (12:45 +0000)
commite145dd0277d225b04b4c724e583374cfd7253847
treeedbce47b775813a01738c870fe0928674f004056
parent5621be9997dc99d06416f05263cd710a6924ad27
Do magic to mix reads and writes on stdio FILE-based ports.
* fports.c (FPORT_READ_SAFE, FPORT_WRITE_SAFE, FPORT_ALL_OKAY):
New macros.
(pre_read, pre_write): New functions.
(local_fgetc, local_fgets, local_ffwrite, local_fputc,
local_fputs): Call them.
(local_fflush): Mark the port as ready for reading and writing.
(scm_stdio_to_port): Set the FPORT_READ_SAFE, FPORT_WRITE_SAFE
flags on new port objects.  This might not be accurate --- who
knows what state the FILE * is in when we get it --- but it won't
do extraneous calls to fflush or fseek, so it's no worse than the
behavior before this change.
* ports.h: Add comment.
Centralize the creation of port objects based on stdio FILE * in
fports.c; don't just throw them together anywhere.
* fports.c (scm_stdio_to_port): Make NAME a SCM value, which is
what the rest of Guile wants.  Don't set the revealed count;
that's only appropriate for stdin, stdout, stderr.
(scm_standard_stream_to_port): This function does set the revealed
count.
* init.c (scm_init_standard_ports): Use scm_standard_stream_to_port,
not scm_stdio_to_port.
* filesys.c (scm_open): Call scm_stdio_to_port; don't write it out.
* fports.c (scm_open_file): Same.
* posix.c (scm_pipe): Same.
* socket.c (scm_sock_fd_to_port): Same.
* ioext.c (scm_fdopen): Same.
(scm_freopen): Moved from here to...
* fports.c (scm_freopen): ... here.  This is really something that
munges the internals of an fport, so it should go here.
* fports.h (scm_stdio_to_port): Adjust prototype.
(scm_standard_stream_to_port, scm_freopen): New protoypes.
* ioext.h (scm_freopen): Prototype removed.
libguile/fports.c