On Monday 08 September 2025 19:09:24 Pali Rohár wrote:
> On Monday 08 September 2025 09:19:52 Kirill Makurin wrote:
> > Speaking of _setmode, I wonder if there is a way to obtain which
> > translation mode is set on particular file descriptor? It's kinda dumb that
> > there is no way to get it other than calling _setmode (it returns previous
> > translation mode).
>
> I will look at this. I have an idea how to get this information.
Here is implementation of _getmode() macro. It reads the mode
information from global array __pioinfo which is exported since
msvcrt.dll (4.2) version and then all later version. But it is not in
UCRT. That _pioinfo(fh) definition I used more times in the past.
#include <stdio.h>
#include <stddef.h>
#include <fcntl.h>
#include <windows.h>
typedef struct {
intptr_t osfhnd;
char osfile;
char pipech;
int lockinitflag;
CRITICAL_SECTION lock;
char textmode;
char reminders[];
} ioinfo;
extern __declspec(dllimport) ioinfo* __pioinfo[];
#define IOINFO_L2E 5
#define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
#define _ioinfo_size (_msize((void*)__pioinfo[0]) / IOINFO_ARRAY_ELTS)
#define _pioinfo(fh) ((ioinfo *) \
(((size_t)__pioinfo[(fh) >> IOINFO_L2E])/* * to head of array ioinfo [] */\
/* offset to the head of a particular ioinfo struct */ \
+ (((fh) & (IOINFO_ARRAY_ELTS - 1)) * _ioinfo_size)) \
)
#define FTEXT 0x80
#define _osfile(fh) (_pioinfo(fh)->osfile)
#define _textmode(fh) (_ioinfo_size >= (offsetof(ioinfo, textmode) +
sizeof(char)) ? (_pioinfo(fh)->textmode) : 0)
#define _getmode(fh) ((!(_osfile(fh) & FTEXT)) ? _O_BINARY : (_textmode(fh)
== 0) ? _O_TEXT : _O_WTEXT)
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public