+/* ------------------------------------------------------------------------- */
+
+/* child_process.status values */
+enum {
+ STATUS_READ_ERROR = -1,
+ STATUS_READ_READY,
+ STATUS_READ_IN_PROGRESS,
+ STATUS_READ_FAILED,
+ STATUS_READ_SUCCEEDED,
+ STATUS_READ_ACKNOWLEDGED
+};
+
+/* This structure is used for both pipes and sockets; for
+ a socket, the process handle in pi is NULL. */
+typedef struct _child_process
+{
+ /* File descriptor for sockets and serial port connections, and for
+ reading output from async subprocesses; otherwise -1. */
+ int fd;
+ /* PID for subprocess, either async or not; otherwise -1. */
+ int pid;
+ /* Handle to an event object that is signaled when a read operation
+ is completed, either successfully (in which case there're indeed
+ "characters available") or not. Used by sys_select to wait for
+ output from subprocesses or socket/serial connections. */
+ HANDLE char_avail;
+ /* Handle to an event that is signaled to wake up the reader thread
+ and tell it to try reading more output from a subprocess. */
+ HANDLE char_consumed;
+ /* Handle to the reader thread to read output from a subprocess or a
+ socket or a comm port. */
+ HANDLE thrd;
+ /* Handle to the console window of a subprocess. Used to forcibly
+ terminate it by sys_kill. */
+ HWND hwnd;
+ /* Information about subprocess returned by CreateProcess. Includes
+ handles to the subprocess and its primary thread, and the
+ corresponding process ID and thread ID numbers. The PID is
+ mirrored by the 'pid' member above. The process handle is used
+ to wait on it. */
+ PROCESS_INFORMATION procinfo;
+ /* Status of subprocess/connection and of reading its output. For
+ values, see the enumeration above. */
+ volatile int status;
+ /* Holds a single character read by _sys_read_ahead, when a
+ subprocess has some output ready. */
+ char chr;
+ /* Used for async read operations on serial comm ports. */
+ OVERLAPPED ovl_read;
+ /* Used for async write operations on serial comm ports. */
+ OVERLAPPED ovl_write;
+} child_process;
+
+#define MAXDESC FD_SETSIZE
+#define MAX_CHILDREN MAXDESC/2
+#define CHILD_ACTIVE(cp) ((cp)->char_avail != NULL)
+
+/* parallel array of private info on file handles */
+typedef struct
+{
+ unsigned flags;
+ HANDLE hnd;
+ child_process * cp;
+} filedesc;
+
+extern filedesc fd_info [ MAXDESC ];
+
+/* fd_info flag definitions */
+#define FILE_READ 0x0001
+#define FILE_WRITE 0x0002
+#define FILE_LISTEN 0x0004
+#define FILE_BINARY 0x0010
+#define FILE_LAST_CR 0x0020
+#define FILE_AT_EOF 0x0040
+#define FILE_SEND_SIGCHLD 0x0080
+#define FILE_PIPE 0x0100
+#define FILE_SOCKET 0x0200
+#define FILE_NDELAY 0x0400
+#define FILE_SERIAL 0x0800
+
+extern child_process * new_child (void);
+extern void delete_child (child_process *cp);
+
+/* ------------------------------------------------------------------------- */
+
+/* Equivalent of strerror for W32 error codes. */
+extern char * w32_strerror (int error_no);
+
+/* Validate a pointer. */
+extern int w32_valid_pointer_p (void *, int);
+
+/* Get long (aka "true") form of file name, if it exists. */
+extern BOOL w32_get_long_filename (char * name, char * buf, int size);
+
+/* Get the short (a.k.a. "8+3") form of a file name. */
+extern unsigned int w32_get_short_filename (char *, char *, int);