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