Fix more incompatibilities between MinGW.org and MinGW64 headers
[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
f247498e
JB
27/* #undef const */
28
a8ab93b0
JB
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
3360970a 36/* If you are compiling with a non-C calling convention but need to
e05aebe9 37 declare vararg routines differently, put it here. */
3360970a
KH
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
e05aebe9 42 convention must be whatever standard the libraries expect. */
3360970a
KH
43#define _CALLBACK_ __cdecl
44
e05aebe9
GM
45/* Define HAVE_TIMEVAL if the system supports the BSD style clock values.
46 Look in <sys/time.h> for a timeval structure. */
124abc74 47#define HAVE_TIMEVAL 1
95ed0025 48
69fd7dbf
KS
49/* But our select implementation doesn't allow us to make non-blocking
50 connects. So until that is fixed, this is necessary: */
69fd7dbf
KS
51#define BROKEN_NON_BLOCKING_CONNECT 1
52
401ea527
KS
53/* And the select implementation does 1-byte read-ahead waiting
54 for received packets, so datagrams are broken too. */
401ea527
KS
55#define BROKEN_DATAGRAM_SOCKETS 1
56
124abc74 57#define MAIL_USE_SYSTEM_LOCK 1
95ed0025 58
ef099b57
JB
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
343a2aef
EZ
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
95ed0025
RS
85/* ============================================================ */
86
e05aebe9
GM
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). */
95ed0025 92
f247498e
JB
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
109typedef 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. */
127extern char *getenv ();
128#endif
129
553fabe7
EZ
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, so define our override before including any
133 system headers. */
134#define _WIN32_WINNT 0x0400
135
136/* Make a leaner executable. */
137#define WIN32_LEAN_AND_MEAN 1
138
f247498e
JB
139#ifdef HAVE_STRINGS_H
140#include "strings.h"
141#endif
d6dae14b 142#include <sys/types.h>
a6fc3b5c 143
95ed0025
RS
144#ifndef MAXPATHLEN
145#define MAXPATHLEN _MAX_PATH
146#endif
147
4a1ba222 148#ifdef HAVE_NTGUI
124abc74 149#define HAVE_WINDOW_SYSTEM 1
124abc74 150#define HAVE_MENUS 1
4a1ba222
GV
151#endif
152
e05aebe9 153/* Get some redefinitions in place. */
4e36126c 154
124abc74
AI
155#ifdef emacs
156
b88b62de
EZ
157#ifdef _W64
158/* MinGW64 specific stuff. */
159#define USE_NO_MINGW_SETJMP_TWO_ARGS 1
160/* Make sure 'struct timespec' and 'struct timezone' are defined. */
161#include <sys/types.h>
162#include <time.h>
163#endif
164
a6fc3b5c
EZ
165#ifdef _MSC_VER
166#include <sys/timeb.h>
167#include <sys/stat.h>
168#include <signal.h>
3ad924ba
EZ
169
170/* MSVC gets link-time errors without these redirections. */
171#define fstat(a, b) sys_fstat(a, b)
172#define stat(a, b) sys_stat(a, b)
173#define utime sys_utime
a6fc3b5c
EZ
174#endif
175
e05aebe9 176/* Calls that are emulated or shadowed. */
7f470eff 177#undef chdir
4e36126c 178#define chdir sys_chdir
7f470eff 179#undef chmod
4e36126c 180#define chmod sys_chmod
7f470eff 181#undef close
4e36126c 182#define close sys_close
7f470eff 183#undef creat
4e36126c
GV
184#define creat sys_creat
185#define ctime sys_ctime
7f470eff 186#undef dup
4e36126c 187#define dup sys_dup
7f470eff 188#undef dup2
4e36126c
GV
189#define dup2 sys_dup2
190#define fopen sys_fopen
191#define link sys_link
97a93095 192#define localtime sys_localtime
4e36126c 193#define mkdir sys_mkdir
7f470eff 194#undef mktemp
4e36126c 195#define mktemp sys_mktemp
7f470eff 196#undef open
4e36126c
GV
197#define open sys_open
198#define pipe sys_pipe
7f470eff 199#undef read
4e36126c
GV
200#define read sys_read
201#define rename sys_rename
202#define rmdir sys_rmdir
203#define select sys_select
c9240d7a 204#define pselect sys_select
4e36126c 205#define sleep sys_sleep
a14724c8 206#define strerror sys_strerror
7f470eff 207#undef unlink
4e36126c 208#define unlink sys_unlink
b0728617
EZ
209/* This prototype is needed because some files include config.h
210 _after_ the standard headers, so sys_unlink gets no prototype from
211 stdio.h or io.h. */
212extern int sys_unlink (const char *);
7f470eff 213#undef write
4e36126c
GV
214#define write sys_write
215
e05aebe9 216/* Subprocess calls that are emulated. */
4e36126c 217#define spawnve sys_spawnve
4e36126c
GV
218#define kill sys_kill
219#define signal sys_signal
220
4d7e6e51 221/* Internal signals. */
5101529e 222#define emacs_raise(sig) emacs_abort()
4d7e6e51 223
e05aebe9 224/* termcap.c calls that are emulated. */
91eac4bb
JB
225#define tputs sys_tputs
226#define tgetstr sys_tgetstr
227
e05aebe9 228/* cm.c calls that are emulated. */
91eac4bb
JB
229#define chcheckmagic sys_chcheckmagic
230#define cmcostinit sys_cmcostinit
231#define cmgoto sys_cmgoto
232#define cmputc sys_cmputc
233#define Wcm_clear sys_Wcm_clear
234
124abc74
AI
235#endif /* emacs */
236
e05aebe9 237/* Map to MSVC names. */
4e36126c
GV
238#define execlp _execlp
239#define execvp _execvp
47d7532e 240#define fdatasync _commit
4e36126c 241#define fdopen _fdopen
23bf9efb 242#ifndef fileno
4e36126c 243#define fileno _fileno
23bf9efb 244#endif
a5a7d30f
AI
245#define fsync _commit
246#define ftruncate _chsize
4e36126c 247#define getpid _getpid
9b67f3aa
EZ
248#ifdef _MSC_VER
249typedef int pid_t;
8c9afb46
EZ
250#define snprintf _snprintf
251#define strtoll _strtoi64
9b67f3aa 252#endif
4e36126c 253#define isatty _isatty
4e36126c
GV
254#define _longjmp longjmp
255#define lseek _lseek
256#define popen _popen
257#define pclose _pclose
4e36126c 258#define umask _umask
8c9afb46 259#ifndef _MSC_VER
719072f5 260#define utimbuf _utimbuf
8c9afb46 261#endif
bfba227f
AI
262#define strdup _strdup
263#define strupr _strupr
264#define strnicmp _strnicmp
265#define stricmp _stricmp
266#define tzset _tzset
e37b3faf 267
a68089e4
EZ
268/* We cannot include system header process.h, since there's src/process.h. */
269int _getpid (void);
270
8a0c01dd
EZ
271/* Include time.h before redirecting tzname, since MSVC's time.h
272 defines _tzname to call a function, but also declares tzname a
273 2-element array. Having the redirection before including the
274 header thus has the effect of declaring a function that returns an
275 array, and triggers an error message. */
276#include <time.h>
bfba227f 277#define tzname _tzname
8c9afb46 278#if !defined (_MSC_VER) || (_MSC_VER < 1400)
3ad924ba 279#undef utime
bc5f466c 280#define utime _utime
e37b3faf 281#endif
95ed0025 282
696056c2
EZ
283/* 'struct timespec' is used by time-related functions in lib/ and
284 elsewhere, but we don't use lib/time.h where the structure is
285 defined. */
553fabe7
EZ
286/* MinGW64 defines 'struct timespec' and _TIMESPEC_DEFINED in sys/types.h. */
287#ifndef _TIMESPEC_DEFINED
696056c2
EZ
288struct timespec
289{
290 time_t tv_sec; /* seconds */
291 long int tv_nsec; /* nanoseconds */
292};
553fabe7 293#endif
696056c2 294
a68089e4
EZ
295/* Required for functions in lib/time_r.c, since we don't use lib/time.h. */
296extern struct tm *gmtime_r (time_t const * restrict, struct tm * restrict);
297extern struct tm *localtime_r (time_t const * restrict, struct tm * restrict);
298
cd91fb4b 299#ifdef _MSC_VER
e05aebe9 300/* This is hacky, but is necessary to avoid warnings about macro
cd91fb4b
EZ
301 redefinitions using the MSVC compilers, since, when __STDC__ is
302 undefined or zero, those compilers declare functions like fileno,
303 lseek, and chdir, for which we defined macros above. */
7f470eff
GV
304#ifndef __STDC__
305#define __STDC__ 1
306#define MUST_UNDEF__STDC__
307#endif
308#include <direct.h>
309#include <io.h>
310#include <stdio.h>
311#ifdef MUST_UNDEF__STDC__
312#undef __STDC__
313#undef MUST_UNDEF__STDC__
314#endif
cd91fb4b
EZ
315#else /* !_MSC_VER */
316#include <direct.h>
317#include <io.h>
318#include <stdio.h>
319#endif /* !_MSC_VER */
7f470eff 320
e05aebe9 321/* Defines that we need that aren't in the standard signal.h. */
95ed0025
RS
322#define SIGHUP 1 /* Hang up */
323#define SIGQUIT 3 /* Quit process */
324#define SIGTRAP 5 /* Trace trap */
325#define SIGKILL 9 /* Die, die die */
326#define SIGPIPE 13 /* Write on pipe with no readers */
327#define SIGALRM 14 /* Alarm */
328#define SIGCHLD 18 /* Death of child */
c06c382a 329#define SIGPROF 19 /* Profiling */
95ed0025 330
bfba227f
AI
331#ifndef NSIG
332#define NSIG 23
333#endif
334
66447e07
EZ
335#ifndef ENOTSUP
336#define ENOTSUP ENOSYS
337#endif
338
a68089e4
EZ
339#ifdef _MSC_VER
340typedef int sigset_t;
341typedef int ssize_t;
342#endif
343
553fabe7
EZ
344#ifndef _POSIX /* MinGW64 */
345typedef _sigset_t sigset_t;
346#endif
347
a68089e4
EZ
348typedef void (_CALLBACK_ *signal_handler) (int);
349extern signal_handler sys_signal (int, signal_handler);
350
351struct sigaction {
352 int sa_flags;
353 void (_CALLBACK_ *sa_handler)(int);
354 sigset_t sa_mask;
355};
356#define SA_RESTART 0
357#define SIG_BLOCK 1
358#define SIG_SETMASK 2
359#define SIG_UNBLOCK 3
360
361extern int sigemptyset (sigset_t *);
362extern int sigaddset (sigset_t *, int);
363extern int sigfillset (sigset_t *);
364extern int sigprocmask (int, const sigset_t *, sigset_t *);
365extern int pthread_sigmask (int, const sigset_t *, sigset_t *);
366extern int sigismember (const sigset_t *, int);
367extern int setpgrp (int, int);
368extern int sigaction (int, const struct sigaction *, struct sigaction *);
369extern int alarm (int);
370
371extern int sys_kill (int, int);
372
373
95ed0025
RS
374/* For integration with MSDOS support. */
375#define getdisk() (_getdrive () - 1)
445f44d2
RS
376#ifdef emacs
377#define getdefdir(_drv, _buf) ((_buf[0] = (_drv + 'A' - 1), _buf[1] = ':', _buf[2] = '/', _buf[3] = 0), 1)
378#else
95ed0025 379#define getdefdir(_drv, _buf) _getdcwd (_drv, _buf, MAXPATHLEN)
445f44d2 380#endif
95ed0025 381
bfba227f
AI
382extern char *get_emacs_configuration (void);
383extern char *get_emacs_configuration_options (void);
3360970a 384#define EMACS_CONFIGURATION get_emacs_configuration ()
bfba227f 385#define EMACS_CONFIG_OPTIONS get_emacs_configuration_options ()
3360970a 386
4e36126c
GV
387/* Define this so that winsock.h definitions don't get included with
388 windows.h. For this to have proper effect, config.h must always be
389 included before windows.h. */
95ed0025 390#define _WINSOCKAPI_ 1
bfba227f 391#define _WINSOCK_H
95ed0025 392
1cd47f14 393/* Defines size_t and alloca (). */
8c9afb46 394#ifdef emacs
bfba227f
AI
395#define malloc e_malloc
396#define free e_free
397#define realloc e_realloc
398#define calloc e_calloc
399#endif
a6fc3b5c
EZ
400#ifdef _MSC_VER
401#define alloca _alloca
402#else
1cd47f14 403#include <malloc.h>
a6fc3b5c 404#endif
1cd47f14 405
f247498e 406#include <stdlib.h>
3360970a 407#include <sys/stat.h>
3360970a 408
e05aebe9 409/* Define for those source files that do not include enough NT system files. */
3360970a
KH
410#ifndef NULL
411#ifdef __cplusplus
412#define NULL 0
413#else
414#define NULL ((void *)0)
415#endif
416#endif
896c0d8b 417
4a1ba222 418/* For proper declaration of environ. */
bfba227f
AI
419#ifndef sys_nerr
420#define sys_nerr _sys_nerr
421#endif
4a1ba222 422
75ceee05
EZ
423/* This must be after including stdlib.h, which defines putenv on MinGW. */
424#ifdef putenv
425# undef putenv
426#endif
427#define putenv sys_putenv
a16e75cd 428extern int sys_putenv (char *);
75ceee05 429
eef5ce6e 430extern int getloadavg (double *, int);
a68089e4 431extern int getpagesize (void);
eef5ce6e 432
8c0905ac
EZ
433extern void * memrchr (void const *, int, size_t);
434
435
62aba0d4 436#if defined (__MINGW32__)
f247498e
JB
437
438/* Define to 1 if the system has the type `long long int'. */
439# define HAVE_LONG_LONG_INT 1
440
441/* Define to 1 if the system has the type `unsigned long long int'. */
442# define HAVE_UNSIGNED_LONG_LONG_INT 1
443
62aba0d4 444#endif
f247498e 445
62aba0d4
FP
446#ifdef _MSC_VER
447# if defined(_WIN64)
448typedef __int64 EMACS_INT;
449typedef unsigned __int64 EMACS_UINT;
450# define EMACS_INT_MAX LLONG_MAX
451# define PRIuMAX "llu"
452# define pI "ll"
453/* Fix a bug in MSVC headers : stdint.h */
454# define _INTPTR 2
455# elif defined(_WIN32)
f247498e
JB
456/* Temporarily disable wider-than-pointer integers until they're tested more.
457 Build with CFLAGS='-DWIDE_EMACS_INT' to try them out. */
458
62aba0d4 459# ifdef WIDE_EMACS_INT
f247498e
JB
460
461/* Use pre-C99-style 64-bit integers. */
71f88e00
PE
462typedef __int64 EMACS_INT;
463typedef unsigned __int64 EMACS_UINT;
62aba0d4
FP
464# define EMACS_INT_MAX LLONG_MAX
465# define PRIuMAX "llu"
466# define pI "I64"
467# else
468typedef int EMACS_INT;
469typedef unsigned int EMACS_UINT;
470# define EMACS_INT_MAX LONG_MAX
471# define PRIuMAX "lu"
472# define pI "l"
473# endif
f247498e 474# endif
f247498e
JB
475#endif
476
517d7b9f 477/* We need a little extra space, see ../../lisp/loadup.el. */
ff709c3a 478#define SYSTEM_PURESIZE_EXTRA 50000
e3be3bfd 479
34374650
PE
480#define DATA_START get_data_start ()
481
7f470eff
GV
482/* For unexec to work on Alpha systems, we need to put Emacs'
483 initialized data into a separate section from the CRT initialized
484 data (because the Alpha linker freely reorders data variables, even
485 across libraries, so our data and the CRT data get intermingled).
486
487 Starting with MSVC 5.0, we must also place the uninitialized data
488 into its own section. VC5 intermingles uninitialized data from the CRT
489 between Emacs' static uninitialized data and its public uninitialized
490 data. A separate .bss section for Emacs groups both static and
517d7b9f 491 public uninitialized together.
7f470eff 492
517d7b9f 493 Note that unexw32.c relies on this fact, and must be modified
7f470eff
GV
494 accordingly if this section name is changed, or if this pragma is
495 removed. Also, obviously, all files that define initialized data
496 must include config.h to pick up this pragma. */
497
e05aebe9 498/* Names must be < 8 bytes. */
52c7f9ee 499#ifdef _MSC_VER
7f470eff
GV
500#pragma data_seg("EMDATA")
501#pragma bss_seg("EMBSS")
52c7f9ee 502#endif
7f470eff
GV
503
504/* #define FULL_DEBUG */
505/* #define EMACSDEBUG */
506
507#ifdef EMACSDEBUG
508extern void _DebPrint (const char *fmt, ...);
509#define DebPrint(stuff) _DebPrint stuff
510#else
511#define DebPrint(stuff)
512#endif
513
62aba0d4
FP
514#ifdef _MSC_VER
515#if _MSC_VER >= 800 && !defined(__cplusplus)
516/* Unnamed type definition in parentheses.
517 A structure, union, or enumerated type with no name is defined in a
518 parenthetical expression. The type definition is meaningless. */
519#pragma warning(disable:4116)
520/* 'argument' : conversion from 'type1' to 'type2', possible loss of
521 data A floating point type was converted to an integer type. A
522 possible loss of data may have occurred. */
523#pragma warning(disable:4244)
524/* Negative integral constant converted to unsigned type.
525 An expression converts a negative integer constant to an unsigned type.
526 The result of the expression is probably meaningless. */
527#pragma warning(disable:4308)
528#endif
529#endif
17a2cbbd
DC
530#define TERM_HEADER "w32term.h"
531
532
3360970a 533/* ============================================================ */