Commit | Line | Data |
---|---|---|
e588809c JR |
1 | #ifndef EMACS_W32_H |
2 | #define EMACS_W32_H | |
b3fa71dc | 3 | |
95ed0025 | 4 | /* Support routines for the NT version of Emacs. |
ba318903 | 5 | Copyright (C) 1994, 2001-2014 Free Software Foundation, Inc. |
95ed0025 RS |
6 | |
7 | This file is part of GNU Emacs. | |
8 | ||
b9b1cc14 | 9 | GNU Emacs is free software: you can redistribute it and/or modify |
95ed0025 | 10 | it under the terms of the GNU General Public License as published by |
b9b1cc14 GM |
11 | the Free Software Foundation, either version 3 of the License, or |
12 | (at your option) any later version. | |
95ed0025 RS |
13 | |
14 | GNU Emacs is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
b9b1cc14 | 20 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
95ed0025 | 21 | |
0fda9b75 DC |
22 | #ifdef CYGWIN |
23 | #error "w32.h is not compatible with Cygwin" | |
24 | #endif | |
25 | ||
26 | #include <windows.h> | |
27 | ||
7482f2ec | 28 | |
b3fa71dc GV |
29 | /* File descriptor set emulation. */ |
30 | ||
31 | /* MSVC runtime library has limit of 64 descriptors by default */ | |
32 | #define FD_SETSIZE 64 | |
33 | typedef struct { | |
34 | unsigned int bits[FD_SETSIZE / 32]; | |
35 | } fd_set; | |
36 | ||
37 | /* standard access macros */ | |
38 | #define FD_SET(n, p) \ | |
39 | do { \ | |
40 | if ((n) < FD_SETSIZE) { \ | |
41 | (p)->bits[(n)/32] |= (1 << (n)%32); \ | |
42 | } \ | |
43 | } while (0) | |
44 | #define FD_CLR(n, p) \ | |
45 | do { \ | |
46 | if ((n) < FD_SETSIZE) { \ | |
47 | (p)->bits[(n)/32] &= ~(1 << (n)%32); \ | |
48 | } \ | |
49 | } while (0) | |
50 | #define FD_ISSET(n, p) ((n) < FD_SETSIZE ? ((p)->bits[(n)/32] & (1 << (n)%32)) : 0) | |
51 | #define FD_ZERO(p) memset((p), 0, sizeof(fd_set)) | |
52 | ||
95ed0025 | 53 | #define SELECT_TYPE fd_set |
95ed0025 | 54 | |
b3fa71dc GV |
55 | /* ------------------------------------------------------------------------- */ |
56 | ||
57 | /* child_process.status values */ | |
58 | enum { | |
59 | STATUS_READ_ERROR = -1, | |
60 | STATUS_READ_READY, | |
61 | STATUS_READ_IN_PROGRESS, | |
62 | STATUS_READ_FAILED, | |
63 | STATUS_READ_SUCCEEDED, | |
64 | STATUS_READ_ACKNOWLEDGED | |
65 | }; | |
66 | ||
67 | /* This structure is used for both pipes and sockets; for | |
68 | a socket, the process handle in pi is NULL. */ | |
69 | typedef struct _child_process | |
70 | { | |
d3d14b40 EZ |
71 | /* File descriptor for sockets and serial port connections, and for |
72 | reading output from async subprocesses; otherwise -1. */ | |
73 | int fd; | |
74 | /* PID for subprocess, either async or not; otherwise -1. */ | |
75 | int pid; | |
76 | /* Handle to an event object that is signaled when a read operation | |
77 | is completed, either successfully (in which case there're indeed | |
78 | "characters available") or not. Used by sys_select to wait for | |
79 | output from subprocesses or socket/serial connections. */ | |
80 | HANDLE char_avail; | |
81 | /* Handle to an event that is signaled to wake up the reader thread | |
82 | and tell it to try reading more output from a subprocess. */ | |
83 | HANDLE char_consumed; | |
84 | /* Handle to the reader thread to read output from a subprocess or a | |
85 | socket or a comm port. */ | |
86 | HANDLE thrd; | |
87 | /* Handle to the console window of a subprocess. Used to forcibly | |
88 | terminate it by sys_kill. */ | |
89 | HWND hwnd; | |
90 | /* Information about subprocess returned by CreateProcess. Includes | |
91 | handles to the subprocess and its primary thread, and the | |
92 | corresponding process ID and thread ID numbers. The PID is | |
93 | mirrored by the 'pid' member above. The process handle is used | |
94 | to wait on it. */ | |
95 | PROCESS_INFORMATION procinfo; | |
96 | /* Status of subprocess/connection and of reading its output. For | |
97 | values, see the enumeration above. */ | |
98 | volatile int status; | |
99 | /* Holds a single character read by _sys_read_ahead, when a | |
100 | subprocess has some output ready. */ | |
101 | char chr; | |
102 | /* Used for async read operations on serial comm ports. */ | |
103 | OVERLAPPED ovl_read; | |
104 | /* Used for async write operations on serial comm ports. */ | |
105 | OVERLAPPED ovl_write; | |
b3fa71dc GV |
106 | } child_process; |
107 | ||
108 | #define MAXDESC FD_SETSIZE | |
109 | #define MAX_CHILDREN MAXDESC/2 | |
110 | #define CHILD_ACTIVE(cp) ((cp)->char_avail != NULL) | |
111 | ||
112 | /* parallel array of private info on file handles */ | |
113 | typedef struct | |
114 | { | |
115 | unsigned flags; | |
116 | HANDLE hnd; | |
117 | child_process * cp; | |
118 | } filedesc; | |
119 | ||
120 | extern filedesc fd_info [ MAXDESC ]; | |
121 | ||
122 | /* fd_info flag definitions */ | |
ead2be98 GV |
123 | #define FILE_READ 0x0001 |
124 | #define FILE_WRITE 0x0002 | |
d18f316e | 125 | #define FILE_LISTEN 0x0004 |
ead2be98 GV |
126 | #define FILE_BINARY 0x0010 |
127 | #define FILE_LAST_CR 0x0020 | |
128 | #define FILE_AT_EOF 0x0040 | |
129 | #define FILE_SEND_SIGCHLD 0x0080 | |
130 | #define FILE_PIPE 0x0100 | |
131 | #define FILE_SOCKET 0x0200 | |
2c0c4d35 | 132 | #define FILE_NDELAY 0x0400 |
d888760c | 133 | #define FILE_SERIAL 0x0800 |
b3fa71dc GV |
134 | |
135 | extern child_process * new_child (void); | |
136 | extern void delete_child (child_process *cp); | |
137 | ||
138 | /* ------------------------------------------------------------------------- */ | |
139 | ||
7482f2ec AI |
140 | /* Equivalent of strerror for W32 error codes. */ |
141 | extern char * w32_strerror (int error_no); | |
142 | ||
0c5c0e3d EZ |
143 | /* Validate a pointer. */ |
144 | extern int w32_valid_pointer_p (void *, int); | |
145 | ||
bb06745d GV |
146 | /* Get long (aka "true") form of file name, if it exists. */ |
147 | extern BOOL w32_get_long_filename (char * name, char * buf, int size); | |
95ed0025 | 148 | |
1fd201bb EZ |
149 | /* Get the short (a.k.a. "8+3") form of a file name. */ |
150 | extern unsigned int w32_get_short_filename (char *, char *, int); | |
151 | ||
95ed0025 | 152 | /* Prepare our standard handles for proper inheritance by child processes. */ |
177c0ea7 | 153 | extern void prepare_standard_handles (int in, int out, |
95ed0025 RS |
154 | int err, HANDLE handles[4]); |
155 | ||
156 | /* Reset our standard handles to their original state. */ | |
177c0ea7 | 157 | extern void reset_standard_handles (int in, int out, |
95ed0025 RS |
158 | int err, HANDLE handles[4]); |
159 | ||
46c91229 | 160 | /* Return the string resource associated with KEY of type TYPE. */ |
fbd6baed | 161 | extern LPBYTE w32_get_resource (char * key, LPDWORD type); |
b3fa71dc | 162 | |
3f940c5a | 163 | extern void release_listen_threads (void); |
16b22fef EZ |
164 | extern void init_ntproc (int); |
165 | extern void term_ntproc (int); | |
5197f0c2 | 166 | extern HANDLE maybe_load_unicows_dll (void); |
52c7f9ee | 167 | extern void globals_of_w32 (void); |
46c91229 | 168 | |
c06c382a EZ |
169 | extern void term_timers (void); |
170 | extern void init_timers (void); | |
171 | ||
c8b67880 KS |
172 | extern int _sys_read_ahead (int fd); |
173 | extern int _sys_wait_accept (int fd); | |
174 | ||
aa15c6bb | 175 | extern Lisp_Object QCloaded_from; |
d07ff9db | 176 | extern HMODULE w32_delayed_load (Lisp_Object); |
0898ca10 | 177 | |
a68089e4 EZ |
178 | extern void init_environment (char **); |
179 | extern void check_windows_init_file (void); | |
180 | extern void syms_of_ntproc (void); | |
181 | extern void syms_of_ntterm (void); | |
1fd201bb | 182 | extern void dostounix_filename (register char *); |
a68089e4 | 183 | extern void unixtodos_filename (register char *); |
1fd201bb | 184 | extern int filename_from_ansi (const char *, char *); |
2d716d75 EZ |
185 | extern int filename_to_ansi (const char *, char *); |
186 | extern int filename_from_utf16 (const wchar_t *, char *); | |
187 | extern int filename_to_utf16 (const char *, wchar_t *); | |
9ab69568 | 188 | extern Lisp_Object ansi_encode_filename (Lisp_Object); |
ec4440cf | 189 | extern int w32_copy_file (const char *, const char *, int, int, int); |
1fd201bb | 190 | |
a68089e4 EZ |
191 | extern BOOL init_winsock (int load_now); |
192 | extern void srandom (int); | |
193 | extern int random (void); | |
194 | ||
70743157 PE |
195 | extern int fchmod (int, mode_t); |
196 | extern int sys_rename_replace (char const *, char const *, BOOL); | |
067428c1 | 197 | extern int pipe2 (int *, int); |
a68089e4 EZ |
198 | |
199 | extern void set_process_dir (char *); | |
200 | extern int sys_spawnve (int, char *, char **, char **); | |
b0728617 | 201 | extern void register_child (pid_t, int); |
a68089e4 EZ |
202 | |
203 | extern void sys_sleep (int); | |
a68089e4 EZ |
204 | extern int sys_link (const char *, const char *); |
205 | ||
e061a11b TZ |
206 | #ifdef HAVE_GNUTLS |
207 | #include <gnutls/gnutls.h> | |
208 | ||
209 | /* GnuTLS pull (read from remote) interface. */ | |
210 | extern ssize_t emacs_gnutls_pull (gnutls_transport_ptr_t p, | |
211 | void* buf, size_t sz); | |
212 | ||
213 | /* GnuTLS push (write to remote) interface. */ | |
214 | extern ssize_t emacs_gnutls_push (gnutls_transport_ptr_t p, | |
215 | const void* buf, size_t sz); | |
216 | #endif /* HAVE_GNUTLS */ | |
217 | ||
e588809c | 218 | #endif /* EMACS_W32_H */ |