Daniel Engeler <engeler at gmail.com>
[bpt/emacs.git] / src / w32.h
CommitLineData
e588809c
JR
1#ifndef EMACS_W32_H
2#define EMACS_W32_H
b3fa71dc 3
95ed0025 4/* Support routines for the NT version of Emacs.
429ab54e 5 Copyright (C) 1994, 2001, 2002, 2003, 2004, 2005,
8cabe764 6 2006, 2007, 2008 Free Software Foundation, Inc.
95ed0025
RS
7
8This file is part of GNU Emacs.
9
b9b1cc14 10GNU Emacs is free software: you can redistribute it and/or modify
95ed0025 11it under the terms of the GNU General Public License as published by
b9b1cc14
GM
12the Free Software Foundation, either version 3 of the License, or
13(at your option) any later version.
95ed0025
RS
14
15GNU Emacs is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
b9b1cc14 21along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
95ed0025 22
7482f2ec 23
b3fa71dc
GV
24/* File descriptor set emulation. */
25
26/* MSVC runtime library has limit of 64 descriptors by default */
27#define FD_SETSIZE 64
28typedef struct {
29 unsigned int bits[FD_SETSIZE / 32];
30} fd_set;
31
32/* standard access macros */
33#define FD_SET(n, p) \
34 do { \
35 if ((n) < FD_SETSIZE) { \
36 (p)->bits[(n)/32] |= (1 << (n)%32); \
37 } \
38 } while (0)
39#define FD_CLR(n, p) \
40 do { \
41 if ((n) < FD_SETSIZE) { \
42 (p)->bits[(n)/32] &= ~(1 << (n)%32); \
43 } \
44 } while (0)
45#define FD_ISSET(n, p) ((n) < FD_SETSIZE ? ((p)->bits[(n)/32] & (1 << (n)%32)) : 0)
46#define FD_ZERO(p) memset((p), 0, sizeof(fd_set))
47
95ed0025 48#define SELECT_TYPE fd_set
95ed0025 49
b3fa71dc
GV
50/* ------------------------------------------------------------------------- */
51
52/* child_process.status values */
53enum {
54 STATUS_READ_ERROR = -1,
55 STATUS_READ_READY,
56 STATUS_READ_IN_PROGRESS,
57 STATUS_READ_FAILED,
58 STATUS_READ_SUCCEEDED,
59 STATUS_READ_ACKNOWLEDGED
60};
61
62/* This structure is used for both pipes and sockets; for
63 a socket, the process handle in pi is NULL. */
64typedef struct _child_process
65{
66 int fd;
67 int pid;
68 HANDLE char_avail;
69 HANDLE char_consumed;
70 HANDLE thrd;
bb06745d 71 HWND hwnd;
b3fa71dc
GV
72 PROCESS_INFORMATION procinfo;
73 volatile int status;
74 char chr;
d888760c
GM
75 OVERLAPPED ovl_read;
76 OVERLAPPED ovl_write;
b3fa71dc
GV
77} child_process;
78
79#define MAXDESC FD_SETSIZE
80#define MAX_CHILDREN MAXDESC/2
81#define CHILD_ACTIVE(cp) ((cp)->char_avail != NULL)
82
83/* parallel array of private info on file handles */
84typedef struct
85{
86 unsigned flags;
87 HANDLE hnd;
88 child_process * cp;
89} filedesc;
90
91extern filedesc fd_info [ MAXDESC ];
92
93/* fd_info flag definitions */
ead2be98
GV
94#define FILE_READ 0x0001
95#define FILE_WRITE 0x0002
d18f316e 96#define FILE_LISTEN 0x0004
ead2be98
GV
97#define FILE_BINARY 0x0010
98#define FILE_LAST_CR 0x0020
99#define FILE_AT_EOF 0x0040
100#define FILE_SEND_SIGCHLD 0x0080
101#define FILE_PIPE 0x0100
102#define FILE_SOCKET 0x0200
2c0c4d35 103#define FILE_NDELAY 0x0400
d888760c 104#define FILE_SERIAL 0x0800
b3fa71dc
GV
105
106extern child_process * new_child (void);
107extern void delete_child (child_process *cp);
108
109/* ------------------------------------------------------------------------- */
110
7482f2ec
AI
111/* Equivalent of strerror for W32 error codes. */
112extern char * w32_strerror (int error_no);
113
0c5c0e3d
EZ
114/* Validate a pointer. */
115extern int w32_valid_pointer_p (void *, int);
116
bb06745d
GV
117/* Get long (aka "true") form of file name, if it exists. */
118extern BOOL w32_get_long_filename (char * name, char * buf, int size);
95ed0025
RS
119
120/* Prepare our standard handles for proper inheritance by child processes. */
177c0ea7 121extern void prepare_standard_handles (int in, int out,
95ed0025
RS
122 int err, HANDLE handles[4]);
123
124/* Reset our standard handles to their original state. */
177c0ea7 125extern void reset_standard_handles (int in, int out,
95ed0025
RS
126 int err, HANDLE handles[4]);
127
46c91229 128/* Return the string resource associated with KEY of type TYPE. */
fbd6baed 129extern LPBYTE w32_get_resource (char * key, LPDWORD type);
b3fa71dc 130
52c7f9ee
JR
131extern void init_ntproc (void);
132extern void term_ntproc (void);
133extern void globals_of_w32 (void);
134extern void syms_of_w32term (void);
135extern void syms_of_w32fns (void);
136extern void globals_of_w32fns (void);
137extern void syms_of_w32select (void);
138extern void globals_of_w32select (void);
139extern void term_w32select (void);
140extern void syms_of_w32menu (void);
141extern void globals_of_w32menu (void);
142extern void syms_of_fontset (void);
46c91229 143
c8b67880
KS
144extern int _sys_read_ahead (int fd);
145extern int _sys_wait_accept (int fd);
146
e588809c 147#endif /* EMACS_W32_H */
ab5796a9
MB
148
149/* arch-tag: 02c36b00-312b-4c4d-a1d9-f905c5e968f0
150 (do not change this comment) */