2022-08-13 20:11:56 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_FD_INTERNAL_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FD_INTERNAL_H_
|
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
|
2023-08-19 13:41:06 +00:00
|
|
|
#define DO_NOTHING 0
|
|
|
|
#define DO_RESTART 1
|
|
|
|
#define DO_EINTR 2
|
|
|
|
|
2023-06-08 11:37:05 +00:00
|
|
|
#define kFdEmpty 0
|
|
|
|
#define kFdFile 1
|
|
|
|
#define kFdSocket 2
|
|
|
|
#define kFdProcess 3
|
|
|
|
#define kFdConsole 4
|
|
|
|
#define kFdSerial 5
|
|
|
|
#define kFdZip 6
|
|
|
|
#define kFdEpoll 7
|
|
|
|
#define kFdReserved 8
|
2022-08-13 20:11:56 +00:00
|
|
|
|
2023-08-08 11:00:29 +00:00
|
|
|
#define kFdTtyEchoing 1 /* read()→write() (ECHO && !ICANON) */
|
|
|
|
#define kFdTtyEchoRaw 2 /* don't ^X visualize control codes */
|
|
|
|
#define kFdTtyMunging 4 /* enable input / output remappings */
|
|
|
|
#define kFdTtyNoCr2Nl 8 /* don't map \r → \n (a.k.a !ICRNL) */
|
2023-08-18 11:55:57 +00:00
|
|
|
#define kFdTtyNoIsigs 16
|
2023-08-08 11:00:29 +00:00
|
|
|
|
2022-08-13 20:11:56 +00:00
|
|
|
struct Fd {
|
2023-08-08 11:00:29 +00:00
|
|
|
char kind;
|
|
|
|
bool zombie;
|
2023-08-18 11:55:57 +00:00
|
|
|
bool dontclose;
|
2023-08-19 13:41:06 +00:00
|
|
|
char buflen;
|
|
|
|
char buf[4];
|
2022-08-13 20:11:56 +00:00
|
|
|
unsigned flags;
|
|
|
|
unsigned mode;
|
|
|
|
int64_t handle;
|
|
|
|
int64_t extra;
|
|
|
|
};
|
|
|
|
|
2023-08-14 05:42:25 +00:00
|
|
|
struct StdinRelay {
|
|
|
|
_Atomic(uint32_t) once;
|
|
|
|
int64_t inisem; /* semaphore to delay 1st read */
|
|
|
|
int64_t handle; /* should == g_fds.p[0].handle */
|
|
|
|
int64_t reader; /* ReadFile() use this instead */
|
|
|
|
int64_t writer; /* only used by WinStdinThread */
|
2023-08-20 09:13:02 +00:00
|
|
|
int64_t thread; /* handle for the stdio thread */
|
2023-08-14 05:42:25 +00:00
|
|
|
};
|
|
|
|
|
2022-08-13 20:11:56 +00:00
|
|
|
struct Fds {
|
2022-10-17 18:02:04 +00:00
|
|
|
_Atomic(int) f; /* lowest free slot */
|
2022-09-09 23:54:28 +00:00
|
|
|
size_t n;
|
|
|
|
struct Fd *p, *e;
|
2023-08-14 05:42:25 +00:00
|
|
|
struct StdinRelay stdin;
|
2022-08-13 20:11:56 +00:00
|
|
|
};
|
|
|
|
|
2023-08-14 05:42:25 +00:00
|
|
|
void WinMainStdin(void);
|
2023-08-19 13:41:06 +00:00
|
|
|
int64_t __resolve_stdin_handle(int64_t);
|
|
|
|
int __munge_terminal_input(char *, uint32_t *);
|
|
|
|
void __echo_terminal_input(struct Fd *, char *, size_t);
|
2023-08-14 05:42:25 +00:00
|
|
|
|
2022-08-13 20:11:56 +00:00
|
|
|
COSMOPOLITAN_C_END_
|
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_FD_INTERNAL_H_ */
|