Merge branch 'emacs-24'
[emacs.git] / nt / inc / ms-w32.h
blobe54ab87c7eb0a44ac0648ee3583665d24c048a0d
1 /* System description file for Windows NT.
3 Copyright (C) 1993-1995, 2001-2014 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
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.
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.
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/>. */
20 /* Define symbols to identify the version of Unix this is.
21 Define all the symbols that apply correctly. */
23 #ifndef WINDOWSNT
24 #define WINDOWSNT
25 #endif
27 #include <mingw_time.h>
29 /* MinGW-w64 gcc does not automotically define a macro for
30 differentiating it fom MinGW gcc. We need to test the presence of
31 __MINGW64_VERSION_MAJOR in _mingw.h: */
32 #ifdef __MINGW32__
33 # include <_mingw.h>
34 # ifdef __MINGW64_VERSION_MAJOR
35 # define MINGW_W64
36 # endif
37 #endif
39 /* #undef const */
41 /* Number of chars of output in the buffer of a stdio stream. */
42 #ifdef __GNU_LIBRARY__
43 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->__bufp - (FILE)->__buffer)
44 #else
45 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_ptr - (FILE)->_base)
46 #endif
48 /* If you are compiling with a non-C calling convention but need to
49 declare vararg routines differently, put it here. */
50 #define _VARARGS_ __cdecl
52 /* If you are providing a function to something that will call the
53 function back (like a signal handler and signal, or main) its calling
54 convention must be whatever standard the libraries expect. */
55 #define _CALLBACK_ __cdecl
57 /* Define HAVE_TIMEVAL if the system supports the BSD style clock values.
58 Look in <sys/time.h> for a timeval structure. */
59 #define HAVE_TIMEVAL 1
61 /* But our select implementation doesn't allow us to make non-blocking
62 connects. So until that is fixed, this is necessary: */
63 #define BROKEN_NON_BLOCKING_CONNECT 1
65 /* And the select implementation does 1-byte read-ahead waiting
66 for received packets, so datagrams are broken too. */
67 #define BROKEN_DATAGRAM_SOCKETS 1
69 #define MAIL_USE_SYSTEM_LOCK 1
71 /* Define to 1 if GCC-style __attribute__ ((__aligned__ (expr))) works. */
72 #ifdef __GNUC__
73 #define HAVE_ATTRIBUTE_ALIGNED 1
74 #endif
76 /* Define to 1 if strtold conforms to C99. */
77 #ifdef __GNUC__
78 #define HAVE_C99_STRTOLD 1
79 #endif
81 #if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
82 # ifndef HAVE___BUILTIN_UNWIND_INIT
83 # define HAVE___BUILTIN_UNWIND_INIT 1
84 # endif
85 #endif
87 /* This isn't perfect, as some systems might have the page file in
88 another place. Also, I suspect that the time stamp of that file
89 might also change when Windows enlarges the file due to
90 insufficient VM. Still, this seems to be the most reliable way;
91 the alternative (of using GetSystemTimes) won't work on laptops
92 that hibernate, because the system clock is stopped then. Other
93 possibility would be to run "net statistics workstation" and parse
94 the output, but that's gross. So this should do; if the file is
95 not there, the boot time will be returned as zero, and filelock.c
96 already handles that. */
97 #define BOOT_TIME_FILE "C:/pagefile.sys"
99 /* ============================================================ */
101 /* Here, add any special hacks needed to make Emacs work on this
102 system. For example, you might define certain system call names
103 that don't exist on your system, or that do different things on
104 your system and must be used only through an encapsulation (which
105 you should place, by convention, in sysdep.c). */
107 #ifdef __GNUC__
108 #ifndef __cplusplus
109 #undef inline
110 #endif
111 #else /* MSVC */
112 #define inline __inline
113 #endif
115 #ifdef __GNUC__
116 /* config.h may have defined already. */
117 # ifndef restrict
118 # define restrict __restrict__
119 # endif
120 #else
121 /* FIXME: should we define to __restrict, which MSVC supports? */
122 # define restrict
123 #endif
125 /* `mode_t' is not defined for MSVC. Define. */
126 #ifdef _MSC_VER
127 typedef unsigned short mode_t;
128 #endif
130 /* A va_copy replacement for MSVC. */
131 #ifdef _MSC_VER
132 # ifdef _WIN64
133 # ifndef va_copy /* Need to be checked (?) */
134 # define va_copy(d,s) ((d) = (s))
135 # endif
136 # else /* not _WIN64 */
137 # define va_copy(d,s) ((d) = (s))
138 # endif /* not _WIN64 */
139 #endif /* _MSC_VER */
141 #ifndef WINDOWSNT
142 /* Some of the files of Emacs which are intended for use with other
143 programs assume that if you have a config.h file, you must declare
144 the type of getenv. */
145 extern char *getenv ();
146 #endif
148 /* Prevent accidental use of features unavailable in older Windows
149 versions we still support. MinGW64 defines this to a higher value
150 in its system headers, and is not really compatible with values
151 lower than 0x0500, so leave it alone. */
152 #ifndef MINGW_W64
153 # define _WIN32_WINNT 0x0400
154 #endif
156 /* Make a leaner executable. */
157 #define WIN32_LEAN_AND_MEAN 1
159 #include <sys/types.h>
161 #ifndef MAXPATHLEN
162 #define MAXPATHLEN _MAX_PATH
163 #endif
165 /* This is used to hold UTF-8 encoded file names. */
166 #define MAX_UTF8_PATH (MAXPATHLEN * 4)
168 #ifdef HAVE_NTGUI
169 # ifndef HAVE_WINDOW_SYSTEM
170 # define HAVE_WINDOW_SYSTEM 1
171 # define POLL_FOR_INPUT 1
172 # endif
173 #endif
175 /* Get some redefinitions in place. */
177 #ifdef emacs
179 #ifdef MINGW_W64
180 /* MinGW64 specific stuff. */
181 /* Make sure 'struct timespec' and 'struct timezone' are defined. */
182 #include <sys/types.h>
183 #include <time.h>
184 /* This prototype avoids MinGW64 compiler warnings due to the fact
185 that time.h is included before localtime is redirected to
186 sys_localtime below. */
187 extern struct tm * sys_localtime (const time_t *);
188 /* MinGW64 uses a 2-argument _setjmp, and setjmp is a macro defined to
189 supply the 2nd arg correctly, so don't use _setjmp directly in that
190 case. */
191 #undef HAVE__SETJMP
192 #endif
194 #ifdef _MSC_VER
195 #include <sys/timeb.h>
196 #include <sys/stat.h>
197 #include <signal.h>
199 /* MSVC gets link-time errors without these redirections. */
200 #define fstat(a, b) sys_fstat(a, b)
201 #define stat(a, b) sys_stat(a, b)
202 #define utime sys_utime
203 #endif
205 /* Calls that are emulated or shadowed. */
206 #undef chdir
207 #define chdir sys_chdir
208 #undef chmod
209 #define chmod sys_chmod
210 #undef close
211 #define close sys_close
212 #undef creat
213 #define creat sys_creat
214 #define ctime sys_ctime
215 #undef dup
216 #define dup sys_dup
217 #undef dup2
218 #define dup2 sys_dup2
219 #define fopen sys_fopen
220 #define link sys_link
221 #define localtime sys_localtime
222 #define mkdir sys_mkdir
223 #undef open
224 #define open sys_open
225 #undef read
226 #define read sys_read
227 #define rename sys_rename
228 #define rmdir sys_rmdir
229 #define select sys_select
230 #define pselect sys_select
231 #define sleep sys_sleep
232 #define strerror sys_strerror
233 #undef unlink
234 #define unlink sys_unlink
235 #undef opendir
236 #define opendir sys_opendir
237 #undef closedir
238 #define closedir sys_closedir
239 #undef readdir
240 #define readdir sys_readdir
241 #undef seekdir
242 #define seekdir sys_seekdir
243 /* This prototype is needed because some files include config.h
244 _after_ the standard headers, so sys_unlink gets no prototype from
245 stdio.h or io.h. */
246 extern int sys_unlink (const char *);
247 #undef write
248 #define write sys_write
249 #undef umask
250 #define umask sys_umask
251 extern int sys_umask (int);
253 /* Subprocess calls that are emulated. */
254 #define spawnve sys_spawnve
255 #define kill sys_kill
256 #define signal sys_signal
258 /* Internal signals. */
259 #define emacs_raise(sig) emacs_abort()
261 /* termcap.c calls that are emulated. */
262 #define tputs sys_tputs
263 #define tgetstr sys_tgetstr
265 /* cm.c calls that are emulated. */
266 #define chcheckmagic sys_chcheckmagic
267 #define cmcostinit sys_cmcostinit
268 #define cmgoto sys_cmgoto
269 #define cmputc sys_cmputc
270 #define Wcm_clear sys_Wcm_clear
272 #endif /* emacs */
274 /* Map to MSVC names. */
275 #define execlp _execlp
276 #define execvp _execvp
277 #define fdatasync _commit
278 #define fdopen _fdopen
279 #define fsync _commit
280 #define ftruncate _chsize
281 #define getpid _getpid
282 #ifdef _MSC_VER
283 typedef int pid_t;
284 #define snprintf _snprintf
285 #define strtoll _strtoi64
286 #define copysign _copysign
287 #endif
288 #define isatty _isatty
289 #define _longjmp longjmp
290 /* MinGW64 defines lseek to invoke lseek64. */
291 #ifndef lseek
292 #define lseek _lseek
293 #endif
294 #define popen _popen
295 #define pclose _pclose
296 #define strdup _strdup
297 #define strupr _strupr
298 #define strnicmp _strnicmp
299 #define stricmp _stricmp
300 #define tzset _tzset
302 /* We cannot include system header process.h, since there's src/process.h. */
303 int _getpid (void);
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>
311 #define tzname _tzname
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. */
316 /* MinGW64 defines 'struct timespec' and _TIMESPEC_DEFINED in sys/types.h. */
317 #ifndef _TIMESPEC_DEFINED
318 struct timespec
320 time_t tv_sec; /* seconds */
321 long int tv_nsec; /* nanoseconds */
323 #endif
325 /* Required for functions in lib/time_r.c, since we don't use lib/time.h. */
326 extern struct tm *gmtime_r (time_t const * restrict, struct tm * restrict);
327 extern struct tm *localtime_r (time_t const * restrict, struct tm * restrict);
329 #ifdef _MSC_VER
330 /* This is hacky, but is necessary to avoid warnings about macro
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. */
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
345 #else /* !_MSC_VER */
346 #include <direct.h>
347 #include <io.h>
348 #include <stdio.h>
349 #endif /* !_MSC_VER */
350 #ifndef fileno
351 #define fileno _fileno
352 #endif
354 /* Defines that we need that aren't in the standard signal.h. */
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 */
362 #define SIGPROF 19 /* Profiling */
364 #ifndef NSIG
365 #define NSIG 23
366 #endif
368 #ifndef ENOTSUP
369 #define ENOTSUP ENOSYS
370 #endif
372 /* In case lib/errno.h is not used. */
373 #ifndef EOPNOTSUPP
374 #define EOPNOTSUPP 130
375 #endif
377 #ifdef _MSC_VER
378 typedef int sigset_t;
379 typedef int ssize_t;
380 #endif
382 #ifdef MINGW_W64
383 #ifndef _POSIX
384 typedef _sigset_t sigset_t;
385 #endif
386 #endif
388 typedef void (_CALLBACK_ *signal_handler) (int);
389 extern signal_handler sys_signal (int, signal_handler);
391 struct sigaction {
392 int sa_flags;
393 void (_CALLBACK_ *sa_handler)(int);
394 sigset_t sa_mask;
396 #define SA_RESTART 0
397 #define SIG_BLOCK 1
398 #define SIG_SETMASK 2
399 #define SIG_UNBLOCK 3
401 extern int sigemptyset (sigset_t *);
402 extern int sigaddset (sigset_t *, int);
403 extern int sigfillset (sigset_t *);
404 extern int sigprocmask (int, const sigset_t *, sigset_t *);
405 /* MinGW64 defines pthread_sigmask as zero in its pthread_signal.h
406 header, but we have an implementation for that function in w32proc.c. */
407 #ifdef pthread_sigmask
408 #undef pthread_sigmask
409 #endif
410 extern int pthread_sigmask (int, const sigset_t *, sigset_t *);
411 extern int sigismember (const sigset_t *, int);
412 extern int setpgrp (int, int);
413 extern int sigaction (int, const struct sigaction *, struct sigaction *);
414 extern int alarm (int);
416 extern int sys_kill (pid_t, int);
419 /* For integration with MSDOS support. */
420 #define getdisk() (_getdrive () - 1)
421 #ifdef emacs
422 #define getdefdir(_drv, _buf) ((_buf[0] = (_drv + 'A' - 1), _buf[1] = ':', _buf[2] = '/', _buf[3] = 0), 1)
423 #else
424 #define getdefdir(_drv, _buf) _getdcwd (_drv, _buf, MAXPATHLEN)
425 #endif
427 #ifndef EMACS_CONFIGURATION
428 extern char *get_emacs_configuration (void);
429 extern char *get_emacs_configuration_options (void);
430 #define EMACS_CONFIGURATION get_emacs_configuration ()
431 #define EMACS_CONFIG_OPTIONS get_emacs_configuration_options ()
432 #endif
434 /* Define this so that winsock.h definitions don't get included with
435 windows.h. For this to have proper effect, config.h must always be
436 included before windows.h. */
437 #define _WINSOCKAPI_ 1
438 #define _WINSOCK_H
440 /* Defines size_t and alloca (). */
441 #include <stdlib.h>
442 #include <sys/stat.h>
443 #ifdef _MSC_VER
444 #define alloca _alloca
445 #else
446 #include <malloc.h>
447 #endif
449 #ifdef emacs
451 typedef void * (* malloc_fn)(size_t);
452 typedef void * (* realloc_fn)(void *, size_t);
453 typedef void (* free_fn)(void *);
455 extern void *malloc_before_dump(size_t);
456 extern void *realloc_before_dump(void *, size_t);
457 extern void free_before_dump(void *);
458 extern void *malloc_after_dump(size_t);
459 extern void *realloc_after_dump(void *, size_t);
460 extern void free_after_dump(void *);
462 extern malloc_fn the_malloc_fn;
463 extern realloc_fn the_realloc_fn;
464 extern free_fn the_free_fn;
466 #define malloc(size) (*the_malloc_fn)(size)
467 #define free(ptr) (*the_free_fn)(ptr)
468 #define realloc(ptr, size) (*the_realloc_fn)(ptr, size)
470 #endif
472 /* Define for those source files that do not include enough NT system files. */
473 #ifndef NULL
474 #ifdef __cplusplus
475 #define NULL 0
476 #else
477 #define NULL ((void *)0)
478 #endif
479 #endif
481 /* For proper declaration of environ. */
482 #ifndef sys_nerr
483 #define sys_nerr _sys_nerr
484 #endif
486 /* This must be after including stdlib.h, which defines putenv on MinGW. */
487 #ifdef putenv
488 # undef putenv
489 #endif
490 #define putenv sys_putenv
491 extern int sys_putenv (char *);
493 extern int getloadavg (double *, int);
494 extern int getpagesize (void);
496 extern void * memrchr (void const *, int, size_t);
498 extern int mkostemp (char *, int);
501 #if defined (__MINGW32__)
503 /* Define to 1 if the system has the type `long long int'. */
504 # ifndef HAVE_LONG_LONG_INT
505 # define HAVE_LONG_LONG_INT 1
506 # endif
508 /* Define to 1 if the system has the type `unsigned long long int'. */
509 # ifndef HAVE_UNSIGNED_LONG_LONG_INT
510 # define HAVE_UNSIGNED_LONG_LONG_INT 1
511 # endif
513 #endif
515 #ifdef _MSC_VER
516 # if defined(_WIN64)
517 typedef __int64 EMACS_INT;
518 typedef unsigned __int64 EMACS_UINT;
519 # define EMACS_INT_MAX LLONG_MAX
520 # define PRIuMAX "llu"
521 # define pI "ll"
522 /* Fix a bug in MSVC headers : stdint.h */
523 # define _INTPTR 2
524 # elif defined(_WIN32)
525 /* Temporarily disable wider-than-pointer integers until they're tested more.
526 Build with CFLAGS='-DWIDE_EMACS_INT' to try them out. */
528 # ifdef WIDE_EMACS_INT
530 /* Use pre-C99-style 64-bit integers. */
531 typedef __int64 EMACS_INT;
532 typedef unsigned __int64 EMACS_UINT;
533 # define EMACS_INT_MAX LLONG_MAX
534 # define PRIuMAX "llu"
535 # define pI "I64"
536 # else
537 typedef int EMACS_INT;
538 typedef unsigned int EMACS_UINT;
539 # define EMACS_INT_MAX LONG_MAX
540 # define PRIuMAX "lu"
541 # define pI "l"
542 # endif
543 # endif
544 #endif
546 /* We need a little extra space, see ../../lisp/loadup.el. */
547 #define SYSTEM_PURESIZE_EXTRA 50000
549 #define DATA_START get_data_start ()
551 /* For unexec to work on Alpha systems, we need to put Emacs'
552 initialized data into a separate section from the CRT initialized
553 data (because the Alpha linker freely reorders data variables, even
554 across libraries, so our data and the CRT data get intermingled).
556 Starting with MSVC 5.0, we must also place the uninitialized data
557 into its own section. VC5 intermingles uninitialized data from the CRT
558 between Emacs' static uninitialized data and its public uninitialized
559 data. A separate .bss section for Emacs groups both static and
560 public uninitialized together.
562 Note that unexw32.c relies on this fact, and must be modified
563 accordingly if this section name is changed, or if this pragma is
564 removed. Also, obviously, all files that define initialized data
565 must include config.h to pick up this pragma. */
567 /* Names must be < 8 bytes. */
568 #ifdef _MSC_VER
569 #pragma data_seg("EMDATA")
570 #pragma bss_seg("EMBSS")
571 #endif
573 /* #define FULL_DEBUG */
574 /* #define EMACSDEBUG */
576 #ifdef EMACSDEBUG
577 extern void _DebPrint (const char *fmt, ...);
578 #define DebPrint(stuff) _DebPrint stuff
579 #else
580 #define DebPrint(stuff)
581 #endif
583 #ifdef _MSC_VER
584 #if _MSC_VER >= 800 && !defined(__cplusplus)
585 /* Unnamed type definition in parentheses.
586 A structure, union, or enumerated type with no name is defined in a
587 parenthetical expression. The type definition is meaningless. */
588 #pragma warning(disable:4116)
589 /* 'argument' : conversion from 'type1' to 'type2', possible loss of
590 data A floating point type was converted to an integer type. A
591 possible loss of data may have occurred. */
592 #pragma warning(disable:4244)
593 /* Negative integral constant converted to unsigned type.
594 An expression converts a negative integer constant to an unsigned type.
595 The result of the expression is probably meaningless. */
596 #pragma warning(disable:4308)
597 #endif
598 #endif
601 /* ============================================================ */