From caf9aae0155540357e2c68e31685772cdad26786 Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Wed, 5 Feb 2025 08:53:24 +1000 Subject: aio: add support for translation binary|text Mainly to support changing stdout,stderr to binary mode on Windows. Signed-off-by: Steve Bennett --- jim-aio.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'jim-aio.c') diff --git a/jim-aio.c b/jim-aio.c index a2b81f5..f43eaac 100644 --- a/jim-aio.c +++ b/jim-aio.c @@ -1666,6 +1666,28 @@ static int aio_cmd_buffering(Jim_Interp *interp, int argc, Jim_Obj *const *argv) return JIM_OK; } +static int aio_cmd_translation(Jim_Interp *interp, int argc, Jim_Obj *const *argv) +{ + enum {OPT_BINARY, OPT_TEXT}; + static const char * const options[] = { + "binary", + "text", + NULL + }; + int opt; + + if (Jim_GetEnum(interp, argv[0], options, &opt, NULL, JIM_ERRMSG) != JIM_OK) { + return JIM_ERR; + } +#if defined(Jim_SetMode) + else { + AioFile *af = Jim_CmdPrivData(interp); + Jim_SetMode(af->fd, opt == OPT_BINARY ? O_BINARY : O_TEXT); + } +#endif + return JIM_OK; +} + static int aio_cmd_readsize(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { AioFile *af = Jim_CmdPrivData(interp); @@ -2182,6 +2204,13 @@ static const jim_subcmd_type aio_command_table[] = { 2, /* Description: Sets or returns write buffering */ }, + { "translation", + "binary|text", + aio_cmd_translation, + 1, + 1, + /* Description: Sets output translation mode */ + }, { "readsize", "?size?", aio_cmd_readsize, -- cgit v1.1