c67f07b99b3707092a006474631403d91646d3c1
[bpt/emacs.git] / nt / inc / ms-w32.h
1 /* System description file for Windows NT.
2
3 Copyright (C) 1993-1995, 2001-2013 Free Software Foundation, Inc.
4
5 This file is part of GNU Emacs.
6
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20 /* Define symbols to identify the version of Unix this is.
21 Define all the symbols that apply correctly. */
22
23 #ifndef WINDOWSNT
24 #define WINDOWSNT
25 #endif
26
27 /* #undef const */
28
29 /* Number of chars of output in the buffer of a stdio stream. */
30 #ifdef __GNU_LIBRARY__
31 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->__bufp - (FILE)->__buffer)
32 #else
33 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_ptr - (FILE)->_base)
34 #endif
35
36 /* If you are compiling with a non-C calling convention but need to
37 declare vararg routines differently, put it here. */
38 #define _VARARGS_ __cdecl
39
40 /* If you are providing a function to something that will call the
41 function back (like a signal handler and signal, or main) its calling
42 convention must be whatever standard the libraries expect. */
43 #define _CALLBACK_ __cdecl
44
45 /* Define HAVE_TIMEVAL if the system supports the BSD style clock values.
46 Look in <sys/time.h> for a timeval structure. */
47 #define HAVE_TIMEVAL 1
48
49 /* But our select implementation doesn't allow us to make non-blocking
50 connects. So until that is fixed, this is necessary: */
51 #define BROKEN_NON_BLOCKING_CONNECT 1
52
53 /* And the select implementation does 1-byte read-ahead waiting
54 for received packets, so datagrams are broken too. */
55 #define BROKEN_DATAGRAM_SOCKETS 1
56
57 #define MAIL_USE_SYSTEM_LOCK 1
58
59 /* Define to 1 if GCC-style __attribute__ ((__aligned__ (expr))) works. */
60 #ifdef __GNUC__
61 #define HAVE_ATTRIBUTE_ALIGNED 1
62 #endif
63
64 /* Define to 1 if strtold conforms to C99. */
65 #ifdef __GNUC__
66 #define HAVE_C99_STRTOLD 1
67 #endif
68
69 #if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
70 #define HAVE___BUILTIN_UNWIND_INIT 1
71 #endif
72
73 /* This isn't perfect, as some systems might have the page file in
74 another place. Also, I suspect that the time stamp of that file
75 might also change when Windows enlarges the file due to
76 insufficient VM. Still, this seems to be the most reliable way;
77 the alternative (of using GetSystemTimes) won't work on laptops
78 that hibernate, because the system clock is stopped then. Other
79 possibility would be to run "net statistics workstation" and parse
80 the output, but that's gross. So this should do; if the file is
81 not there, the boot time will be returned as zero, and filelock.c
82 already handles that. */
83 #define BOOT_TIME_FILE "C:/pagefile.sys"
84
85 /* ============================================================ */
86
87 /* Here, add any special hacks needed to make Emacs work on this
88 system. For example, you might define certain system call names
89 that don't exist on your system, or that do different things on
90 your system and must be used only through an encapsulation (which
91 you should place, by convention, in sysdep.c). */
92
93 #ifdef __GNUC__
94 #ifndef __cplusplus
95 #undef inline
96 #endif
97 #else /* MSVC */
98 #define inline __inline
99 #endif
100
101 #ifdef __GNUC__
102 # define restrict __restrict__
103 #else
104 # define restrict
105 #endif
106
107 /* `mode_t' is not defined for MSVC. Define. */
108 #ifdef _MSC_VER
109 typedef unsigned short mode_t;
110 #endif
111
112 /* A va_copy replacement for MSVC. */
113 #ifdef _MSC_VER
114 # ifdef _WIN64
115 # ifndef va_copy /* Need to be checked (?) */
116 # define va_copy(d,s) ((d) = (s))
117 # endif
118 # else /* not _WIN64 */
119 # define va_copy(d,s) ((d) = (s))
120 # endif /* not _WIN64 */
121 #endif /* _MSC_VER */
122
123 #ifndef WINDOWSNT
124 /* Some of the files of Emacs which are intended for use with other
125 programs assume that if you have a config.h file, you must declare
126 the type of getenv. */
127 extern char *getenv ();
128 #endif
129
130 /* Prevent accidental use of features unavailable in older Windows
131 versions we still support. MinGW64 defines this to a higher value
132 in its system headers, and is not really compatible with values
133 lower than 0x0500, so leave it alone. */
134 #ifndef _W64
135 # define _WIN32_WINNT 0x0400
136 #endif
137
138 /* Make a leaner executable. */
139 #define WIN32_LEAN_AND_MEAN 1
140
141 #ifdef HAVE_STRINGS_H
142 #include "strings.h"
143 #endif
144 #include <sys/types.h>
145
146 #ifndef MAXPATHLEN
147 #define MAXPATHLEN _MAX_PATH
148 #endif
149
150 #ifdef HAVE_NTGUI
151 #define HAVE_WINDOW_SYSTEM 1
152 #define HAVE_MENUS 1
153 #endif
154
155 /* Get some redefinitions in place. */
156
157 #ifdef emacs
158
159 #ifdef _W64
160 /* MinGW64 specific stuff. */
161 /* Make sure 'struct timespec' and 'struct timezone' are defined. */
162 #include <sys/types.h>
163 #include <time.h>
164 /* This prototype avoids MinGW64 compiler warnings due to the fact
165 that time.h is included before localtime is redirected to
166 sys_localtime below. */
167 extern struct tm * sys_localtime (const time_t *);
168 /* MinGW64 uses a 2-argument _setjmp, and setjmp is a macro defined to
169 supply the 2nd arg correctly, so don't use _setjmp directly in that
170 case. */
171 #undef HAVE__SETJMP
172 #endif
173
174 #ifdef _MSC_VER
175 #include <sys/timeb.h>
176 #include <sys/stat.h>
177 #include <signal.h>
178
179 /* MSVC gets link-time errors without these redirections. */
180 #define fstat(a, b) sys_fstat(a, b)
181 #define stat(a, b) sys_stat(a, b)
182 #define utime sys_utime
183 #endif
184
185 /* Calls that are emulated or shadowed. */
186 #undef chdir
187 #define chdir sys_chdir
188 #undef chmod
189 #define chmod sys_chmod
190 #undef close
191 #define close sys_close
192 #undef creat
193 #define creat sys_creat
194 #define ctime sys_ctime
195 #undef dup
196 #define dup sys_dup
197 #undef dup2
198 #define dup2 sys_dup2
199 #define fopen sys_fopen
200 #define link sys_link
201 #define localtime sys_localtime
202 #define mkdir sys_mkdir
203 #undef mktemp
204 #define mktemp sys_mktemp
205 #undef open
206 #define open sys_open
207 #define pipe sys_pipe
208 #undef read
209 #define read sys_read
210 #define rename sys_rename
211 #define rmdir sys_rmdir
212 #define select sys_select
213 #define pselect sys_select
214 #define sleep sys_sleep
215 #define strerror sys_strerror
216 #undef unlink
217 #define unlink sys_unlink
218 /* This prototype is needed because some files include config.h
219 _after_ the standard headers, so sys_unlink gets no prototype from
220 stdio.h or io.h. */
221 extern int sys_unlink (const char *);
222 #undef write
223 #define write sys_write
224
225 /* Subprocess calls that are emulated. */
226 #define spawnve sys_spawnve
227 #define kill sys_kill
228 #define signal sys_signal
229
230 /* Internal signals. */
231 #define emacs_raise(sig) emacs_abort()
232
233 /* termcap.c calls that are emulated. */
234 #define tputs sys_tputs
235 #define tgetstr sys_tgetstr
236
237 /* cm.c calls that are emulated. */
238 #define chcheckmagic sys_chcheckmagic
239 #define cmcostinit sys_cmcostinit
240 #define cmgoto sys_cmgoto
241 #define cmputc sys_cmputc
242 #define Wcm_clear sys_Wcm_clear
243
244 #endif /* emacs */
245
246 /* Map to MSVC names. */
247 #define execlp _execlp
248 #define execvp _execvp
249 #define fdatasync _commit
250 #define fdopen _fdopen
251 #ifndef fileno
252 #define fileno _fileno
253 #endif
254 #define fsync _commit
255 #define ftruncate _chsize
256 #define getpid _getpid
257 #ifdef _MSC_VER
258 typedef int pid_t;
259 #define snprintf _snprintf
260 #define strtoll _strtoi64
261 #define copysign _copysign
262 #endif
263 #define isatty _isatty
264 #define _longjmp longjmp
265 #define lseek _lseek
266 #define popen _popen
267 #define pclose _pclose
268 #define umask _umask
269 #ifndef _MSC_VER
270 #define utimbuf _utimbuf
271 #endif
272 #define strdup _strdup
273 #define strupr _strupr
274 #define strnicmp _strnicmp
275 #define stricmp _stricmp
276 #define tzset _tzset
277
278 /* We cannot include system header process.h, since there's src/process.h. */
279 int _getpid (void);
280
281 /* Include time.h before redirecting tzname, since MSVC's time.h
282 defines _tzname to call a function, but also declares tzname a
283 2-element array. Having the redirection before including the
284 header thus has the effect of declaring a function that returns an
285 array, and triggers an error message. */
286 #include <time.h>
287 #define tzname _tzname
288 #if !defined (_MSC_VER) || (_MSC_VER < 1400)
289 #undef utime
290 #define utime _utime
291 #endif
292
293 /* 'struct timespec' is used by time-related functions in lib/ and
294 elsewhere, but we don't use lib/time.h where the structure is
295 defined. */
296 /* MinGW64 defines 'struct timespec' and _TIMESPEC_DEFINED in sys/types.h. */
297 #ifndef _TIMESPEC_DEFINED
298 struct timespec
299 {
300 time_t tv_sec; /* seconds */
301 long int tv_nsec; /* nanoseconds */
302 };
303 #endif
304
305 /* Required for functions in lib/time_r.c, since we don't use lib/time.h. */
306 extern struct tm *gmtime_r (time_t const * restrict, struct tm * restrict);
307 extern struct tm *localtime_r (time_t const * restrict, struct tm * restrict);
308
309 #ifdef _MSC_VER
310 /* This is hacky, but is necessary to avoid warnings about macro
311 redefinitions using the MSVC compilers, since, when __STDC__ is
312 undefined or zero, those compilers declare functions like fileno,
313 lseek, and chdir, for which we defined macros above. */
314 #ifndef __STDC__
315 #define __STDC__ 1
316 #define MUST_UNDEF__STDC__
317 #endif
318 #include <direct.h>
319 #include <io.h>
320 #include <stdio.h>
321 #ifdef MUST_UNDEF__STDC__
322 #undef __STDC__
323 #undef MUST_UNDEF__STDC__
324 #endif
325 #else /* !_MSC_VER */
326 #include <direct.h>
327 #include <io.h>
328 #include <stdio.h>
329 #endif /* !_MSC_VER */
330
331 /* Defines that we need that aren't in the standard signal.h. */
332 #define SIGHUP 1 /* Hang up */
333 #define SIGQUIT 3 /* Quit process */
334 #define SIGTRAP 5 /* Trace trap */
335 #define SIGKILL 9 /* Die, die die */
336 #define SIGPIPE 13 /* Write on pipe with no readers */
337 #define SIGALRM 14 /* Alarm */
338 #define SIGCHLD 18 /* Death of child */
339 #define SIGPROF 19 /* Profiling */
340
341 #ifndef NSIG
342 #define NSIG 23
343 #endif
344
345 #ifndef ENOTSUP
346 #define ENOTSUP ENOSYS
347 #endif
348
349 #ifdef _MSC_VER
350 typedef int sigset_t;
351 typedef int ssize_t;
352 #endif
353
354 #ifndef _POSIX /* MinGW64 */
355 typedef _sigset_t sigset_t;
356 #endif
357
358 typedef void (_CALLBACK_ *signal_handler) (int);
359 extern signal_handler sys_signal (int, signal_handler);
360
361 struct sigaction {
362 int sa_flags;
363 void (_CALLBACK_ *sa_handler)(int);
364 sigset_t sa_mask;
365 };
366 #define SA_RESTART 0
367 #define SIG_BLOCK 1
368 #define SIG_SETMASK 2
369 #define SIG_UNBLOCK 3
370
371 extern int sigemptyset (sigset_t *);
372 extern int sigaddset (sigset_t *, int);
373 extern int sigfillset (sigset_t *);
374 extern int sigprocmask (int, const sigset_t *, sigset_t *);
375 extern int pthread_sigmask (int, const sigset_t *, sigset_t *);
376 extern int sigismember (const sigset_t *, int);
377 extern int setpgrp (int, int);
378 extern int sigaction (int, const struct sigaction *, struct sigaction *);
379 extern int alarm (int);
380
381 extern int sys_kill (int, int);
382
383
384 /* For integration with MSDOS support. */
385 #define getdisk() (_getdrive () - 1)
386 #ifdef emacs
387 #define getdefdir(_drv, _buf) ((_buf[0] = (_drv + 'A' - 1), _buf[1] = ':', _buf[2] = '/', _buf[3] = 0), 1)
388 #else
389 #define getdefdir(_drv, _buf) _getdcwd (_drv, _buf, MAXPATHLEN)
390 #endif
391
392 extern char *get_emacs_configuration (void);
393 extern char *get_emacs_configuration_options (void);
394 #define EMACS_CONFIGURATION get_emacs_configuration ()
395 #define EMACS_CONFIG_OPTIONS get_emacs_configuration_options ()
396
397 /* Define this so that winsock.h definitions don't get included with
398 windows.h. For this to have proper effect, config.h must always be
399 included before windows.h. */
400 #define _WINSOCKAPI_ 1
401 #define _WINSOCK_H
402
403 /* Defines size_t and alloca (). */
404 #ifdef emacs
405 #define malloc e_malloc
406 #define free e_free
407 #define realloc e_realloc
408 #define calloc e_calloc
409 #endif
410 #ifdef _MSC_VER
411 #define alloca _alloca
412 #else
413 #include <malloc.h>
414 #endif
415
416 #include <stdlib.h>
417 #include <sys/stat.h>
418
419 /* Define for those source files that do not include enough NT system files. */
420 #ifndef NULL
421 #ifdef __cplusplus
422 #define NULL 0
423 #else
424 #define NULL ((void *)0)
425 #endif
426 #endif
427
428 /* For proper declaration of environ. */
429 #ifndef sys_nerr
430 #define sys_nerr _sys_nerr
431 #endif
432
433 /* This must be after including stdlib.h, which defines putenv on MinGW. */
434 #ifdef putenv
435 # undef putenv
436 #endif
437 #define putenv sys_putenv
438 extern int sys_putenv (char *);
439
440 extern int getloadavg (double *, int);
441 extern int getpagesize (void);
442
443 extern void * memrchr (void const *, int, size_t);
444
445
446 #if defined (__MINGW32__)
447
448 /* Define to 1 if the system has the type `long long int'. */
449 # define HAVE_LONG_LONG_INT 1
450
451 /* Define to 1 if the system has the type `unsigned long long int'. */
452 # define HAVE_UNSIGNED_LONG_LONG_INT 1
453
454 #endif
455
456 #ifdef _MSC_VER
457 # if defined(_WIN64)
458 typedef __int64 EMACS_INT;
459 typedef unsigned __int64 EMACS_UINT;
460 # define EMACS_INT_MAX LLONG_MAX
461 # define PRIuMAX "llu"
462 # define pI "ll"
463 /* Fix a bug in MSVC headers : stdint.h */
464 # define _INTPTR 2
465 # elif defined(_WIN32)
466 /* Temporarily disable wider-than-pointer integers until they're tested more.
467 Build with CFLAGS='-DWIDE_EMACS_INT' to try them out. */
468
469 # ifdef WIDE_EMACS_INT
470
471 /* Use pre-C99-style 64-bit integers. */
472 typedef __int64 EMACS_INT;
473 typedef unsigned __int64 EMACS_UINT;
474 # define EMACS_INT_MAX LLONG_MAX
475 # define PRIuMAX "llu"
476 # define pI "I64"
477 # else
478 typedef int EMACS_INT;
479 typedef unsigned int EMACS_UINT;
480 # define EMACS_INT_MAX LONG_MAX
481 # define PRIuMAX "lu"
482 # define pI "l"
483 # endif
484 # endif
485 #endif
486
487 /* We need a little extra space, see ../../lisp/loadup.el. */
488 #define SYSTEM_PURESIZE_EXTRA 50000
489
490 #define DATA_START get_data_start ()
491
492 /* For unexec to work on Alpha systems, we need to put Emacs'
493 initialized data into a separate section from the CRT initialized
494 data (because the Alpha linker freely reorders data variables, even
495 across libraries, so our data and the CRT data get intermingled).
496
497 Starting with MSVC 5.0, we must also place the uninitialized data
498 into its own section. VC5 intermingles uninitialized data from the CRT
499 between Emacs' static uninitialized data and its public uninitialized
500 data. A separate .bss section for Emacs groups both static and
501 public uninitialized together.
502
503 Note that unexw32.c relies on this fact, and must be modified
504 accordingly if this section name is changed, or if this pragma is
505 removed. Also, obviously, all files that define initialized data
506 must include config.h to pick up this pragma. */
507
508 /* Names must be < 8 bytes. */
509 #ifdef _MSC_VER
510 #pragma data_seg("EMDATA")
511 #pragma bss_seg("EMBSS")
512 #endif
513
514 /* #define FULL_DEBUG */
515 /* #define EMACSDEBUG */
516
517 #ifdef EMACSDEBUG
518 extern void _DebPrint (const char *fmt, ...);
519 #define DebPrint(stuff) _DebPrint stuff
520 #else
521 #define DebPrint(stuff)
522 #endif
523
524 #ifdef _MSC_VER
525 #if _MSC_VER >= 800 && !defined(__cplusplus)
526 /* Unnamed type definition in parentheses.
527 A structure, union, or enumerated type with no name is defined in a
528 parenthetical expression. The type definition is meaningless. */
529 #pragma warning(disable:4116)
530 /* 'argument' : conversion from 'type1' to 'type2', possible loss of
531 data A floating point type was converted to an integer type. A
532 possible loss of data may have occurred. */
533 #pragma warning(disable:4244)
534 /* Negative integral constant converted to unsigned type.
535 An expression converts a negative integer constant to an unsigned type.
536 The result of the expression is probably meaningless. */
537 #pragma warning(disable:4308)
538 #endif
539 #endif
540
541
542 /* ============================================================ */