1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-29 19:30:36 +02:00

Add 'set-port-binary/text-mode!' procedure for MinGW.

* libguile/ports.c (scm_init_ports)[O_BINARY]: Define 'O_BINARY'.
[O_TEXT]: Define 'O_TEXT'.
(scm_c_set_port_binary_text_mode_x): New function.
* libguile/ports.h (scm_set_binary_text_mode_x): Declare it.
* module/ice-9/ports.scm (ice-9): Export it as
'set-port-binary/text-mode!'.
* doc/ref/api-io.texi (File Ports): Document it.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2020-11-19 15:08:33 +01:00 committed by Michael Gran
parent 2d82b49cf3
commit d58c9411ae
4 changed files with 57 additions and 0 deletions

View file

@ -1150,6 +1150,19 @@ source of data, but only the value that is returned by
Determine whether @var{obj} is a port that is related to a file.
@end deffn
@deffn {Scheme Procedure} set-port-binary/text-mode! port mode
On MinGW, set the binary/text mode for @var{port}. @var{mode} can be one
of the following:
@table @code
@item O_BINARY
binary mode
@item O_TEXT
text mode
@end table
Only open file ports are supported. On POSIX, this is a no-op.
@end deffn
@node Bytevector Ports
@subsubsection Bytevector Ports

View file

@ -4134,6 +4134,41 @@ SCM_DEFINE (scm_sys_make_void_port, "%make-void-port", 1, 0, 0,
}
#undef FUNC_NAME
SCM_DEFINE (scm_set_port_binary_text_mode_x, "set-port-binary/text-mode!", 2, 0, 0,
(SCM port, SCM mode),
"On MinGW, set the binary/text mode for @var{port}. @var{mode} can be one\n"
"of the following:\n"
"@table @code\n"
"@item O_BINARY\n"
"binary mode\n"
"@item O_TEXT\n"
"text mode\n"
"@end table\n\n"
"Only open file ports are supported. On POSIX, this is a no-op.")
#define FUNC_NAME s_scm_set_port_binary_text_mode_x
{
int cmode = 0;
int fd;
if (scm_is_integer (port))
fd = scm_to_int (port);
else
{
SCM_VALIDATE_OPFPORT (1, port);
fd = SCM_FPORT_FDES (port);
}
SCM_VALIDATE_NUMBER (2, mode);
cmode = scm_to_int (mode);
#if __MINGW32__
_setmode (fd, cmode);
#endif
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
@ -4173,6 +4208,13 @@ scm_init_ports (void)
sym_escape = scm_from_latin1_symbol ("escape");
sym_error = scm_from_latin1_symbol ("error");
#ifdef O_BINARY
scm_c_define ("O_BINARY", scm_from_int (O_BINARY));
#endif
#ifdef O_TEXT
scm_c_define ("O_TEXT", scm_from_int (O_TEXT));
#endif
trampoline_to_c_read_subr =
scm_c_make_gsubr ("port-read", 4, 0, 0,
(scm_t_subr) trampoline_to_c_read);

View file

@ -218,6 +218,7 @@ SCM_API SCM scm_drain_input (SCM port);
SCM_API void scm_end_input (SCM port);
SCM_API SCM scm_force_output (SCM port);
SCM_API void scm_flush (SCM port);
SCM_API SCM scm_set_binary_text_mode_x (SCM port, SCM mode);
SCM_INTERNAL SCM scm_port_random_access_p (SCM port);
SCM_INTERNAL SCM scm_port_read_buffering (SCM port);

View file

@ -69,6 +69,7 @@
port-for-each
flush-all-ports
%make-void-port
set-port-binary/text-mode!
;; Definitions from fports.c.
open-file