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