[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 06/15: Add 'set-mode' procedure for MinGW.
From: |
Jan Nieuwenhuizen |
Subject: |
[Guile-commits] 06/15: Add 'set-mode' procedure for MinGW. |
Date: |
Mon, 12 Apr 2021 05:55:43 -0400 (EDT) |
janneke pushed a commit to branch wip-mingw
in repository guile.
commit a4860cd1c2ca733e5e37a48611ab8e04ee5b2112
Author: Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
AuthorDate: Thu Nov 19 15:08:33 2020 +0100
Add 'set-mode' procedure for MinGW.
* libguile/ports.c (scm_c_set_mode): New function.
(scm_init_ports)[O_BINARY]: Define 'O_BINARY'.
[O_TEXT]: Define 'O_TEXT'.
* module/ice-9/ports.scm (ice-9): Export it as 'set-mode'.
---
libguile/ports.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
libguile/ports.h | 1 +
module/ice-9/ports.scm | 1 +
3 files changed, 47 insertions(+)
diff --git a/libguile/ports.c b/libguile/ports.c
index c25c207..8d8917d 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -4134,6 +4134,44 @@ SCM_DEFINE (scm_sys_make_void_port, "%make-void-port",
1, 0, 0,
}
#undef FUNC_NAME
+SCM_DEFINE (scm_set_mode, "set-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 certain types of ports are supported, most importantly\n"
+ "file ports. On POSIX, this is a no-op.")
+#define FUNC_NAME s_scm_set_mode
+{
+ int cmode = 0;
+ int fd;
+
+#ifdef O_RDONLY
+ scm_c_define ("O_RDONLY", scm_from_int (O_RDONLY));
+#endif
+
+ SCM_VALIDATE_PORT (1, port);
+ if (scm_is_integer (port))
+ fd = scm_to_int (port);
+ else
+ 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 +4211,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);
diff --git a/libguile/ports.h b/libguile/ports.h
index 44ef29d..185c2f3 100644
--- a/libguile/ports.h
+++ b/libguile/ports.h
@@ -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_mode (SCM port, SCM mode);
SCM_INTERNAL SCM scm_port_random_access_p (SCM port);
SCM_INTERNAL SCM scm_port_read_buffering (SCM port);
diff --git a/module/ice-9/ports.scm b/module/ice-9/ports.scm
index b219fee..229c541 100644
--- a/module/ice-9/ports.scm
+++ b/module/ice-9/ports.scm
@@ -69,6 +69,7 @@
port-for-each
flush-all-ports
%make-void-port
+ set-mode
;; Definitions from fports.c.
open-file
- [Guile-commits] branch wip-mingw created (now be9b668), Jan Nieuwenhuizen, 2021/04/12
- [Guile-commits] 02/15: ice-9 ftw: Use 'absolute-file-name?' in 'nftw'., Jan Nieuwenhuizen, 2021/04/12
- [Guile-commits] 10/15: DRAFT Support for x86_64-w64-mingw32., Jan Nieuwenhuizen, 2021/04/12
- [Guile-commits] 15/15: DEBUG guile.cmd: Some Wine help., Jan Nieuwenhuizen, 2021/04/12
- [Guile-commits] 05/15: Compile fix for x86_64-MinGW., Jan Nieuwenhuizen, 2021/04/12
- [Guile-commits] 06/15: Add 'set-mode' procedure for MinGW.,
Jan Nieuwenhuizen <=
- [Guile-commits] 11/15: DRAFT Add partial `scm_fcntl' support for MinGW., Jan Nieuwenhuizen, 2021/04/12
- [Guile-commits] 08/15: Make `read-bytes' suspendable for socket reads on MinGW., Jan Nieuwenhuizen, 2021/04/12
- [Guile-commits] 12/15: Define 'SIGHUP' for MinGW., Jan Nieuwenhuizen, 2021/04/12
- [Guile-commits] 01/15: Document write-line., Jan Nieuwenhuizen, 2021/04/12
- [Guile-commits] 03/15: Fix 'gethostname' prototype for x86_64-MinGW., Jan Nieuwenhuizen, 2021/04/12
- [Guile-commits] 04/15: Clear errno before CreateProcess for MinGW., Jan Nieuwenhuizen, 2021/04/12
- [Guile-commits] 07/15: Add `scm_sigaction_for_thread' stub for MinGW., Jan Nieuwenhuizen, 2021/04/12
- [Guile-commits] 09/15: Install 'mingw_take_signal' on MinGW., Jan Nieuwenhuizen, 2021/04/12
- [Guile-commits] 13/15: Fix 'absolute-file-name?' and others for cross-build to MinGW., Jan Nieuwenhuizen, 2021/04/12
- [Guile-commits] 14/15: guix: Add guile-patched, guile-mingw., Jan Nieuwenhuizen, 2021/04/12