Update copyright notices for 2013.
[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.
ab422c4d 5 Copyright (C) 1994, 2001-2013 Free Software Foundation, Inc.
95ed0025
RS
6
7This file is part of GNU Emacs.
8
b9b1cc14 9GNU Emacs is free software: you can redistribute it and/or modify
95ed0025 10it under the terms of the GNU General Public License as published by
b9b1cc14
GM
11the Free Software Foundation, either version 3 of the License, or
12(at your option) any later version.
95ed0025
RS
13
14GNU Emacs is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
b9b1cc14 20along 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
33typedef 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 */
58enum {
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. */
69typedef struct _child_process
70{
71 int fd;
72 int pid;
73 HANDLE char_avail;
74 HANDLE char_consumed;
75 HANDLE thrd;
bb06745d 76 HWND hwnd;
b3fa71dc
GV
77 PROCESS_INFORMATION procinfo;
78 volatile int status;
79 char chr;
d888760c
GM
80 OVERLAPPED ovl_read;
81 OVERLAPPED ovl_write;
b3fa71dc
GV
82} child_process;
83
84#define MAXDESC FD_SETSIZE
85#define MAX_CHILDREN MAXDESC/2
86#define CHILD_ACTIVE(cp) ((cp)->char_avail != NULL)
87
88/* parallel array of private info on file handles */
89typedef struct
90{
91 unsigned flags;
92 HANDLE hnd;
93 child_process * cp;
94} filedesc;
95
96extern filedesc fd_info [ MAXDESC ];
97
98/* fd_info flag definitions */
ead2be98
GV
99#define FILE_READ 0x0001
100#define FILE_WRITE 0x0002
d18f316e 101#define FILE_LISTEN 0x0004
ead2be98
GV
102#define FILE_BINARY 0x0010
103#define FILE_LAST_CR 0x0020
104#define FILE_AT_EOF 0x0040
105#define FILE_SEND_SIGCHLD 0x0080
106#define FILE_PIPE 0x0100
107#define FILE_SOCKET 0x0200
2c0c4d35 108#define FILE_NDELAY 0x0400
d888760c 109#define FILE_SERIAL 0x0800
b3fa71dc
GV
110
111extern child_process * new_child (void);
112extern void delete_child (child_process *cp);
113
114/* ------------------------------------------------------------------------- */
115
7482f2ec
AI
116/* Equivalent of strerror for W32 error codes. */
117extern char * w32_strerror (int error_no);
118
0c5c0e3d
EZ
119/* Validate a pointer. */
120extern int w32_valid_pointer_p (void *, int);
121
bb06745d
GV
122/* Get long (aka "true") form of file name, if it exists. */
123extern BOOL w32_get_long_filename (char * name, char * buf, int size);
95ed0025
RS
124
125/* Prepare our standard handles for proper inheritance by child processes. */
177c0ea7 126extern void prepare_standard_handles (int in, int out,
95ed0025
RS
127 int err, HANDLE handles[4]);
128
129/* Reset our standard handles to their original state. */
177c0ea7 130extern void reset_standard_handles (int in, int out,
95ed0025
RS
131 int err, HANDLE handles[4]);
132
46c91229 133/* Return the string resource associated with KEY of type TYPE. */
fbd6baed 134extern LPBYTE w32_get_resource (char * key, LPDWORD type);
b3fa71dc 135
16b22fef
EZ
136extern void init_ntproc (int);
137extern void term_ntproc (int);
52c7f9ee 138extern void globals_of_w32 (void);
46c91229 139
c06c382a
EZ
140extern void term_timers (void);
141extern void init_timers (void);
142
c8b67880
KS
143extern int _sys_read_ahead (int fd);
144extern int _sys_wait_accept (int fd);
145
aa15c6bb 146extern Lisp_Object QCloaded_from;
d07ff9db 147extern HMODULE w32_delayed_load (Lisp_Object);
0898ca10 148
a68089e4
EZ
149extern void init_environment (char **);
150extern void check_windows_init_file (void);
151extern void syms_of_ntproc (void);
152extern void syms_of_ntterm (void);
153extern void dostounix_filename (register char *);
154extern void unixtodos_filename (register char *);
155extern BOOL init_winsock (int load_now);
156extern void srandom (int);
157extern int random (void);
158
159extern int sys_pipe (int *);
160
161extern void set_process_dir (char *);
162extern int sys_spawnve (int, char *, char **, char **);
163extern void register_child (int, int);
164
165extern void sys_sleep (int);
166extern char *getwd (char *);
167extern int sys_link (const char *, const char *);
168
169
170
e061a11b
TZ
171#ifdef HAVE_GNUTLS
172#include <gnutls/gnutls.h>
173
174/* GnuTLS pull (read from remote) interface. */
175extern ssize_t emacs_gnutls_pull (gnutls_transport_ptr_t p,
176 void* buf, size_t sz);
177
178/* GnuTLS push (write to remote) interface. */
179extern ssize_t emacs_gnutls_push (gnutls_transport_ptr_t p,
180 const void* buf, size_t sz);
181#endif /* HAVE_GNUTLS */
182
e588809c 183#endif /* EMACS_W32_H */
ab5796a9 184