100
|
1 /* Support routines for the NT version of XEmacs.
|
|
2 Copyright (C) 1994 Free Software Foundation, Inc.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Adapted for XEmacs by David Hobley <david@spook-le0.cia.com.au> */
|
209
|
22 /* Sync'ed with Emacs 19.34.6 by Marc Paquette <marcpa@cam.org> */
|
100
|
23
|
|
24 /* #define FULL_DEBUG */
|
|
25
|
398
|
26 #ifndef INCLUDED_nt_h_
|
|
27 #define INCLUDED_nt_h_
|
|
28
|
239
|
29 #ifdef DEBUG_XEMACS
|
100
|
30 #define DebPrint(stuff) _DebPrint stuff
|
|
31 #else
|
|
32 #define DebPrint(stuff)
|
|
33 #endif
|
|
34
|
|
35 #define R_OK 4
|
|
36 #define W_OK 2
|
398
|
37 #ifdef X_OK
|
|
38 #undef X_OK
|
|
39 #endif
|
100
|
40 #define X_OK 1
|
|
41 #define F_OK 0
|
|
42
|
|
43 /* File descriptor set emulation. */
|
|
44
|
239
|
45 #if 0 /* These are defined in winsock.h.
|
|
46 FD_SETSIZE is defined 64. Let's not full the runtime. */
|
|
47
|
211
|
48 /* The MSVC multithreaded statically-linked runtime library has limit
|
|
49 of 256 descriptors by default (the single-threaded static library
|
|
50 has a limit of 64 descriptors, and the DLL versions both have a
|
|
51 limit of 512). Beware. Should this be set to 512? */
|
|
52 #define FD_SETSIZE 256
|
100
|
53 typedef struct {
|
|
54 unsigned int bits[FD_SETSIZE / 32];
|
|
55 } fd_set;
|
|
56
|
|
57 /* standard access macros */
|
|
58 #define FD_SET(n, p) \
|
|
59 do { \
|
|
60 if ((n) < FD_SETSIZE) { \
|
|
61 (p)->bits[(n)/32] |= (1 << (n)%32); \
|
|
62 } \
|
|
63 } while (0)
|
|
64 #define FD_CLR(n, p) \
|
|
65 do { \
|
|
66 if ((n) < FD_SETSIZE) { \
|
|
67 (p)->bits[(n)/32] &= ~(1 << (n)%32); \
|
|
68 } \
|
|
69 } while (0)
|
|
70 #define FD_ISSET(n, p) ((n) < FD_SETSIZE ? ((p)->bits[(n)/32] & (1 << (n)%32)) : 0)
|
|
71 #define FD_ZERO(p) memset((p), 0, sizeof(fd_set))
|
|
72
|
|
73 #define SELECT_TYPE fd_set
|
239
|
74 #define MAXDESC FD_SETSIZE
|
|
75
|
|
76 #endif /* 0 */
|
100
|
77
|
|
78 /* ------------------------------------------------------------------------- */
|
|
79
|
|
80 /* child_process.status values */
|
|
81 enum {
|
|
82 STATUS_READ_ERROR = -1,
|
|
83 STATUS_READ_READY,
|
|
84 STATUS_READ_IN_PROGRESS,
|
|
85 STATUS_READ_FAILED,
|
|
86 STATUS_READ_SUCCEEDED,
|
|
87 STATUS_READ_ACKNOWLEDGED
|
|
88 };
|
|
89
|
|
90 /* This structure is used for both pipes and sockets; for
|
|
91 a socket, the process handle in pi is NULL. */
|
|
92 typedef struct _child_process
|
|
93 {
|
|
94 int fd;
|
|
95 int pid;
|
|
96 HANDLE char_avail;
|
|
97 HANDLE char_consumed;
|
|
98 HANDLE thrd;
|
209
|
99 HWND hwnd;
|
100
|
100 PROCESS_INFORMATION procinfo;
|
|
101 volatile int status;
|
|
102 char chr;
|
|
103 } child_process;
|
|
104
|
|
105 #define MAX_CHILDREN MAXDESC/2
|
|
106 #define CHILD_ACTIVE(cp) ((cp)->char_avail != NULL)
|
|
107
|
|
108 /* parallel array of private info on file handles */
|
|
109 typedef struct
|
|
110 {
|
|
111 unsigned flags;
|
|
112 HANDLE hnd;
|
|
113 child_process * cp;
|
|
114 } filedesc;
|
|
115
|
|
116 extern filedesc fd_info [ MAXDESC ];
|
|
117
|
|
118 /* fd_info flag definitions */
|
|
119 #define FILE_READ 0x0001
|
|
120 #define FILE_WRITE 0x0002
|
|
121 #define FILE_BINARY 0x0010
|
209
|
122 #define FILE_LAST_CR 0x0020
|
|
123 #define FILE_AT_EOF 0x0040
|
|
124 #define FILE_SEND_SIGCHLD 0x0080
|
100
|
125 #define FILE_PIPE 0x0100
|
|
126 #define FILE_SOCKET 0x0200
|
|
127
|
|
128 extern child_process * new_child (void);
|
|
129 extern void delete_child (child_process *cp);
|
|
130
|
|
131 /* ------------------------------------------------------------------------- */
|
|
132
|
209
|
133 /* Get long (aka "true") form of file name, if it exists. */
|
|
134 extern BOOL win32_get_long_filename (char * name, char * buf, int size);
|
100
|
135
|
|
136 /* Prepare our standard handles for proper inheritance by child processes. */
|
|
137 extern void prepare_standard_handles (int in, int out,
|
|
138 int err, HANDLE handles[4]);
|
|
139
|
|
140 /* Reset our standard handles to their original state. */
|
|
141 extern void reset_standard_handles (int in, int out,
|
|
142 int err, HANDLE handles[4]);
|
|
143
|
|
144 /* Return the string resource associated with KEY of type TYPE. */
|
|
145 extern LPBYTE nt_get_resource (char * key, LPDWORD type);
|
|
146
|
288
|
147 void set_process_dir (const char * dir);
|
|
148 time_t convert_time (FILETIME ft);
|
|
149
|
100
|
150 extern void init_ntproc ();
|
|
151 extern void term_ntproc ();
|
|
152
|
398
|
153 #endif /* INCLUDED_nt_h_ */
|