Avoid MinGW64 compiler warnings.
[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 #endif
262 #define isatty _isatty
263 #define _longjmp longjmp
264 #define lseek _lseek
265 #define popen _popen
266 #define pclose _pclose
267 #define umask _umask
268 #ifndef _MSC_VER
269 #define utimbuf _utimbuf
270 #endif
271 #define strdup _strdup
272 #define strupr _strupr
273 #define strnicmp _strnicmp
274 #define stricmp _stricmp
275 #define tzset _tzset
276
277 /* We cannot include system header process.h, since there's src/process.h. */
278 int _getpid (void);
279
280 /* Include time.h before redirecting tzname, since MSVC's time.h
281 defines _tzname to call a function, but also declares tzname a
282 2-element array. Having the redirection before including the
283 header thus has the effect of declaring a function that returns an
284 array, and triggers an error message. */
285 #include <time.h>
286 #define tzname _tzname
287 #if !defined (_MSC_VER) || (_MSC_VER < 1400)
288 #undef utime
289 #define utime _utime
290 #endif
291
292 /* 'struct timespec' is used by time-related functions in lib/ and
293 elsewhere, but we don't use lib/time.h where the structure is
294 defined. */
295 /* MinGW64 defines 'struct timespec' and _TIMESPEC_DEFINED in sys/types.h. */
296 #ifndef _TIMESPEC_DEFINED
297 struct timespec
298 {
299 time_t tv_sec; /* seconds */
300 long int tv_nsec; /* nanoseconds */
301 };
302 #endif
303
304 /* Required for functions in lib/time_r.c, since we don't use lib/time.h. */
305 extern struct tm *gmtime_r (time_t const * restrict, struct tm * restrict);
306 extern struct tm *localtime_r (time_t const * restrict, struct tm * restrict);
307
308 #ifdef _MSC_VER
309 /* This is hacky, but is necessary to avoid warnings about macro
310 redefinitions using the MSVC compilers, since, when __STDC__ is
311 undefined or zero, those compilers declare functions like fileno,
312 lseek, and chdir, for which we defined macros above. */
313 #ifndef __STDC__
314 #define __STDC__ 1
315 #define MUST_UNDEF__STDC__
316 #endif
317 #include <direct.h>
318 #include <io.h>
319 #include <stdio.h>
320 #ifdef MUST_UNDEF__STDC__
321 #undef __STDC__
322 #undef MUST_UNDEF__STDC__
323 #endif
324 #else /* !_MSC_VER */
325 #include <direct.h>
326 #include <io.h>
327 #include <stdio.h>
328 #endif /* !_MSC_VER */
329
330 /* Defines that we need that aren't in the standard signal.h. */
331 #define SIGHUP 1 /* Hang up */
332 #define SIGQUIT 3 /* Quit process */
333 #define SIGTRAP 5 /* Trace trap */
334 #define SIGKILL 9 /* Die, die die */
335 #define SIGPIPE 13 /* Write on pipe with no readers */
336 #define SIGALRM 14 /* Alarm */
337 #define SIGCHLD 18 /* Death of child */
338 #define SIGPROF 19 /* Profiling */
339
340 #ifndef NSIG
341 #define NSIG 23
342 #endif
343
344 #ifndef ENOTSUP
345 #define ENOTSUP ENOSYS
346 #endif
347
348 #ifdef _MSC_VER
349 typedef int sigset_t;
350 typedef int ssize_t;
351 #endif
352
353 #ifndef _POSIX /* MinGW64 */
354 typedef _sigset_t sigset_t;
355 #endif
356
357 typedef void (_CALLBACK_ *signal_handler) (int);
358 extern signal_handler sys_signal (int, signal_handler);
359
360 struct sigaction {
361 int sa_flags;
362 void (_CALLBACK_ *sa_handler)(int);
363 sigset_t sa_mask;
364 };
365 #define SA_RESTART 0
366 #define SIG_BLOCK 1
367 #define SIG_SETMASK 2
368 #define SIG_UNBLOCK 3
369
370 extern int sigemptyset (sigset_t *);
371 extern int sigaddset (sigset_t *, int);
372 extern int sigfillset (sigset_t *);
373 extern int sigprocmask (int, const sigset_t *, sigset_t *);
374 extern int pthread_sigmask (int, const sigset_t *, sigset_t *);
375 extern int sigismember (const sigset_t *, int);
376 extern int setpgrp (int, int);
377 extern int sigaction (int, const struct sigaction *, struct sigaction *);
378 extern int alarm (int);
379
380 extern int sys_kill (int, int);
381
382
383 /* For integration with MSDOS support. */
384 #define getdisk() (_getdrive () - 1)
385 #ifdef emacs
386 #define getdefdir(_drv, _buf) ((_buf[0] = (_drv + 'A' - 1), _buf[1] = ':', _buf[2] = '/', _buf[3] = 0), 1)
387 #else
388 #define getdefdir(_drv, _buf) _getdcwd (_drv, _buf, MAXPATHLEN)
389 #endif
390
391 extern char *get_emacs_configuration (void);
392 extern char *get_emacs_configuration_options (void);
393 #define EMACS_CONFIGURATION get_emacs_configuration ()
394 #define EMACS_CONFIG_OPTIONS get_emacs_configuration_options ()
395
396 /* Define this so that winsock.h definitions don't get included with
397 windows.h. For this to have proper effect, config.h must always be
398 included before windows.h. */
399 #define _WINSOCKAPI_ 1
400 #define _WINSOCK_H
401
402 /* Defines size_t and alloca (). */
403 #ifdef emacs
404 #define malloc e_malloc
405 #define free e_free
406 #define realloc e_realloc
407 #define calloc e_calloc
408 #endif
409 #ifdef _MSC_VER
410 #define alloca _alloca
411 #else
412 #include <malloc.h>
413 #endif
414
415 #include <stdlib.h>
416 #include <sys/stat.h>
417
418 /* Define for those source files that do not include enough NT system files. */
419 #ifndef NULL
420 #ifdef __cplusplus
421 #define NULL 0
422 #else
423 #define NULL ((void *)0)
424 #endif
425 #endif
426
427 /* For proper declaration of environ. */
428 #ifndef sys_nerr
429 #define sys_nerr _sys_nerr
430 #endif
431
432 /* This must be after including stdlib.h, which defines putenv on MinGW. */
433 #ifdef putenv
434 # undef putenv
435 #endif
436 #define putenv sys_putenv
437 extern int sys_putenv (char *);
438
439 extern int getloadavg (double *, int);
440 extern int getpagesize (void);
441
442 extern void * memrchr (void const *, int, size_t);
443
444
445 #if defined (__MINGW32__)
446
447 /* Define to 1 if the system has the type `long long int'. */
448 # define HAVE_LONG_LONG_INT 1
449
450 /* Define to 1 if the system has the type `unsigned long long int'. */
451 # define HAVE_UNSIGNED_LONG_LONG_INT 1
452
453 #endif
454
455 #ifdef _MSC_VER
456 # if defined(_WIN64)
457 typedef __int64 EMACS_INT;
458 typedef unsigned __int64 EMACS_UINT;
459 # define EMACS_INT_MAX LLONG_MAX
460 # define PRIuMAX "llu"
461 # define pI "ll"
462 /* Fix a bug in MSVC headers : stdint.h */
463 # define _INTPTR 2
464 # elif defined(_WIN32)
465 /* Temporarily disable wider-than-pointer integers until they're tested more.
466 Build with CFLAGS='-DWIDE_EMACS_INT' to try them out. */
467
468 # ifdef WIDE_EMACS_INT
469
470 /* Use pre-C99-style 64-bit integers. */
471 typedef __int64 EMACS_INT;
472 typedef unsigned __int64 EMACS_UINT;
473 # define EMACS_INT_MAX LLONG_MAX
474 # define PRIuMAX "llu"
475 # define pI "I64"
476 # else
477 typedef int EMACS_INT;
478 typedef unsigned int EMACS_UINT;
479 # define EMACS_INT_MAX LONG_MAX
480 # define PRIuMAX "lu"
481 # define pI "l"
482 # endif
483 # endif
484 #endif
485
486 /* We need a little extra space, see ../../lisp/loadup.el. */
487 #define SYSTEM_PURESIZE_EXTRA 50000
488
489 #define DATA_START get_data_start ()
490
491 /* For unexec to work on Alpha systems, we need to put Emacs'
492 initialized data into a separate section from the CRT initialized
493 data (because the Alpha linker freely reorders data variables, even
494 across libraries, so our data and the CRT data get intermingled).
495
496 Starting with MSVC 5.0, we must also place the uninitialized data
497 into its own section. VC5 intermingles uninitialized data from the CRT
498 between Emacs' static uninitialized data and its public uninitialized
499 data. A separate .bss section for Emacs groups both static and
500 public uninitialized together.
501
502 Note that unexw32.c relies on this fact, and must be modified
503 accordingly if this section name is changed, or if this pragma is
504 removed. Also, obviously, all files that define initialized data
505 must include config.h to pick up this pragma. */
506
507 /* Names must be < 8 bytes. */
508 #ifdef _MSC_VER
509 #pragma data_seg("EMDATA")
510 #pragma bss_seg("EMBSS")
511 #endif
512
513 /* #define FULL_DEBUG */
514 /* #define EMACSDEBUG */
515
516 #ifdef EMACSDEBUG
517 extern void _DebPrint (const char *fmt, ...);
518 #define DebPrint(stuff) _DebPrint stuff
519 #else
520 #define DebPrint(stuff)
521 #endif
522
523 #ifdef _MSC_VER
524 #if _MSC_VER >= 800 && !defined(__cplusplus)
525 /* Unnamed type definition in parentheses.
526 A structure, union, or enumerated type with no name is defined in a
527 parenthetical expression. The type definition is meaningless. */
528 #pragma warning(disable:4116)
529 /* 'argument' : conversion from 'type1' to 'type2', possible loss of
530 data A floating point type was converted to an integer type. A
531 possible loss of data may have occurred. */
532 #pragma warning(disable:4244)
533 /* Negative integral constant converted to unsigned type.
534 An expression converts a negative integer constant to an unsigned type.
535 The result of the expression is probably meaningless. */
536 #pragma warning(disable:4308)
537 #endif
538 #endif
539 #define TERM_HEADER "w32term.h"
540
541
542 /* ============================================================ */