1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #ifndef WINDOWSNT
24 #define WINDOWSNT
25 #endif
26
27 #include <mingw_time.h>
28
29
30
31
32 #ifdef __MINGW32__
33 # include <_mingw.h>
34 # ifdef __MINGW64_VERSION_MAJOR
35 # define MINGW_W64
36 # endif
37 # if defined __MINGW32_VERSION && __MINGW32_VERSION >= 5001000L
38
39 # undef __POSIX_2008_DEPRECATED
40 # define __POSIX_2008_DEPRECATED
41 # endif
42
43
44 # ifndef _WIN32_WINNT_WIN2K
45 # define _WIN32_WINNT_WIN2K 0x0500
46 # endif
47 # ifndef _WIN32_WINNT_WINXP
48 # define _WIN32_WINNT_WINXP 0x0501
49 # endif
50 # ifndef _WIN32_WINNT_WS03
51 # define _WIN32_WINNT_WS03 0x0502
52 # endif
53 # ifndef _WIN32_WINNT_VISTA
54 # define _WIN32_WINNT_VISTA 0x0600
55 # endif
56 # ifndef _WIN32_WINNT_WIN7
57 # define _WIN32_WINNT_WIN7 0x0601
58 # endif
59 # ifndef _WIN32_WINNT_WIN8
60 # define _WIN32_WINNT_WIN8 0x0602
61 # endif
62 # ifndef _WIN32_WINNT_WINBLUE
63 # define _WIN32_WINNT_WINBLUE 0x0603
64 # endif
65 # ifndef _WIN32_WINNT_WIN10
66 # define _WIN32_WINNT_WIN10 0x0A00
67 # endif
68 #endif
69
70
71
72
73 #ifdef __GNU_LIBRARY__
74 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->__bufp - (FILE)->__buffer)
75 #else
76 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_ptr - (FILE)->_base)
77 #endif
78
79
80
81 #define _VARARGS_ __cdecl
82
83
84
85
86 #define _CALLBACK_ __cdecl
87
88
89
90 #define HAVE_TIMEVAL 1
91
92
93
94 #define BROKEN_DATAGRAM_SOCKETS 1
95
96 #define MAIL_USE_SYSTEM_LOCK 1
97
98
99 #ifdef __GNUC__
100 #define HAVE_ATTRIBUTE_ALIGNED 1
101 #endif
102
103
104 #ifdef __GNUC__
105 #define HAVE_C99_STRTOLD 1
106 #endif
107
108 #if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
109 # ifndef HAVE___BUILTIN_UNWIND_INIT
110 # define HAVE___BUILTIN_UNWIND_INIT 1
111 # endif
112 #endif
113
114
115
116
117
118
119
120
121
122
123
124 #define BOOT_TIME_FILE "C:/pagefile.sys"
125
126
127
128
129
130
131
132
133
134 #ifdef __GNUC__
135 #ifndef __cplusplus
136 #undef inline
137 #endif
138 #else
139 #define inline __inline
140 #endif
141
142 #ifdef __GNUC__
143
144 # ifndef restrict
145 # define restrict __restrict__
146 # endif
147 #else
148
149 # define restrict
150 #endif
151
152
153 #ifdef _MSC_VER
154 typedef unsigned short mode_t;
155 #endif
156
157
158 #ifdef _MSC_VER
159 # ifdef _WIN64
160 # ifndef va_copy
161 # define va_copy(d,s) ((d) = (s))
162 # endif
163 # else
164 # define va_copy(d,s) ((d) = (s))
165 # endif
166 #endif
167
168 #ifndef WINDOWSNT
169
170
171
172 extern char *getenv ();
173 #endif
174
175
176
177
178
179 #ifndef MINGW_W64
180 # undef _WIN32_WINNT
181 # define _WIN32_WINNT 0x0400
182 #endif
183
184
185 #define WIN32_LEAN_AND_MEAN
186
187 #include <sys/types.h>
188
189 #ifndef MAXPATHLEN
190 #define MAXPATHLEN _MAX_PATH
191 #endif
192
193
194 #define MAX_UTF8_PATH (MAXPATHLEN * 4)
195
196 #ifdef HAVE_NTGUI
197 # ifndef HAVE_WINDOW_SYSTEM
198 # define HAVE_WINDOW_SYSTEM 1
199 # define POLL_FOR_INPUT 1
200 # endif
201 #endif
202
203
204
205 #ifdef emacs
206
207 #ifdef MINGW_W64
208
209
210 #include <sys/types.h>
211 #include <time.h>
212
213
214
215 extern struct tm * sys_localtime (const time_t *);
216
217
218
219 #undef HAVE__SETJMP
220
221
222
223
224
225
226 #undef HAVE_GAI_STRERROR
227 #endif
228
229
230 #include <setjmp.h>
231 typedef jmp_buf sigjmp_buf;
232 #ifdef MINGW_W64
233
234
235
236
237 #define sigsetjmp(j,m) __builtin_setjmp(j)
238 #else
239 #define sigsetjmp(j,m) setjmp(j)
240 #endif
241 extern void w32_reset_stack_overflow_guard (void);
242
243 #ifdef _MSC_VER
244 #include <sys/timeb.h>
245 #include <sys/stat.h>
246 #include <signal.h>
247
248
249 #define fstat(a, b) sys_fstat(a, b)
250 #define stat(a, b) sys_stat(a, b)
251 #define utime sys_utime
252 #endif
253
254
255 #undef chdir
256 #define chdir sys_chdir
257 #undef chmod
258 #define chmod sys_chmod
259 #undef close
260 #define close sys_close
261 #undef creat
262 #define creat sys_creat
263 #define ctime sys_ctime
264 #undef dup
265 #define dup sys_dup
266 #undef dup2
267 #define dup2 sys_dup2
268 #define fopen sys_fopen
269 #define link sys_link
270 #define localtime sys_localtime
271 #undef read
272 #define read sys_read
273 #define rename sys_rename
274 #define rmdir sys_rmdir
275 #define select sys_select
276 #define pselect sys_select
277 #define sleep sys_sleep
278 #define strerror sys_strerror
279 #undef unlink
280 #define unlink sys_unlink
281 #undef opendir
282 #define opendir sys_opendir
283 #undef closedir
284 #define closedir sys_closedir
285 #undef readdir
286 #define readdir sys_readdir
287 #undef seekdir
288 #define seekdir sys_seekdir
289
290
291
292 extern int sys_unlink (const char *);
293 #undef write
294 #define write sys_write
295 #undef umask
296 #define umask sys_umask
297 extern int sys_umask (int);
298 #define clock sys_clock
299
300
301 #define spawnve sys_spawnve
302 #define kill sys_kill
303 #define signal sys_signal
304
305
306 #define emacs_raise(sig) emacs_abort()
307
308
309 #define tputs sys_tputs
310 #define tgetstr sys_tgetstr
311
312
313 #define chcheckmagic sys_chcheckmagic
314 #define cmcostinit sys_cmcostinit
315 #define cmgoto sys_cmgoto
316 #define cmputc sys_cmputc
317 #define Wcm_clear sys_Wcm_clear
318
319 #endif
320
321
322 #undef open
323 #define open sys_open
324
325
326 #define execlp _execlp
327 #define execvp _execvp
328 #include <stdint.h>
329 extern intptr_t _execvp (const char *, char **);
330 #define tcdrain _commit
331 #define fdopen _fdopen
332 #define fsync _commit
333 #define ftruncate _chsize
334 #define getpid _getpid
335 #ifdef _MSC_VER
336 typedef int pid_t;
337 #define snprintf _snprintf
338 #define strtoll _strtoi64
339 #define copysign _copysign
340 #endif
341 #define isatty _isatty
342 #define _longjmp longjmp
343
344 #ifndef lseek
345 #define lseek _lseek
346 #endif
347 #define popen _popen
348 #define pclose _pclose
349 #define strdup _strdup
350 #define strupr _strupr
351 #define strnicmp _strnicmp
352 #define stricmp _stricmp
353 #define tzset _tzset
354
355
356 int _getpid (void);
357
358
359
360
361
362
363 #include <time.h>
364 #define tzname _tzname
365
366
367 extern struct tm *gmtime_r (time_t const * restrict, struct tm * restrict);
368 extern struct tm *localtime_r (time_t const * restrict, struct tm * restrict);
369
370 #ifdef _MSC_VER
371
372
373
374
375 #ifndef __STDC__
376 #define __STDC__ 1
377 #define MUST_UNDEF__STDC__
378 #endif
379 #include <direct.h>
380 #include <io.h>
381 #include <stdio.h>
382 #ifdef MUST_UNDEF__STDC__
383 #undef __STDC__
384 #undef MUST_UNDEF__STDC__
385 #endif
386 #else
387 #include <direct.h>
388 #include <io.h>
389 #include <stdio.h>
390 #endif
391 #ifndef fileno
392 #define fileno _fileno
393 #endif
394
395
396 #define SIGHUP 1
397 #define SIGQUIT 3
398 #define SIGTRAP 5
399 #define SIGKILL 9
400 #define SIGPIPE 13
401 #define SIGALRM 14
402 #define SIGCHLD 18
403 #define SIGPROF 19
404
405 #ifndef NSIG
406 #define NSIG 23
407 #endif
408
409 #ifndef ENOTSUP
410 #define ENOTSUP ENOSYS
411 #endif
412
413
414 #ifndef EOPNOTSUPP
415 #define EOPNOTSUPP 130
416 #endif
417
418 #ifdef _MSC_VER
419 typedef int sigset_t;
420 typedef int ssize_t;
421 #endif
422
423 #ifdef MINGW_W64
424 #ifndef _POSIX
425 typedef _sigset_t sigset_t;
426 #endif
427 #endif
428
429 typedef void (_CALLBACK_ *signal_handler) (int);
430 extern signal_handler sys_signal (int, signal_handler);
431
432 struct sigaction {
433 int sa_flags;
434 void (_CALLBACK_ *sa_handler)(int);
435 sigset_t sa_mask;
436 };
437 #define SA_RESTART 0
438 #define SIG_BLOCK 1
439 #define SIG_SETMASK 2
440 #define SIG_UNBLOCK 3
441
442 extern int sigemptyset (sigset_t *);
443 extern int sigaddset (sigset_t *, int);
444 extern int sigfillset (sigset_t *);
445 extern int sigprocmask (int, const sigset_t *, sigset_t *);
446
447
448 #ifdef pthread_sigmask
449 #undef pthread_sigmask
450 #endif
451 extern int pthread_sigmask (int, const sigset_t *, sigset_t *);
452 extern int sigismember (const sigset_t *, int);
453 extern int setpgrp (int, int);
454 extern int sigaction (int, const struct sigaction *, struct sigaction *);
455 extern int alarm (int);
456
457 extern int sys_kill (pid_t, int);
458
459 extern void explicit_bzero (void *, size_t);
460
461
462 #define getdisk() (_getdrive () - 1)
463 #ifdef emacs
464 #define getdefdir(_drv, _buf) ((_buf[0] = (_drv + 'A' - 1), _buf[1] = ':', _buf[2] = '/', _buf[3] = 0), 1)
465 #else
466 #define getdefdir(_drv, _buf) _getdcwd (_drv, _buf, MAXPATHLEN)
467 #endif
468
469 #ifndef EMACS_CONFIGURATION
470 extern char *get_emacs_configuration (void);
471 extern char *get_emacs_configuration_options (void);
472 #define EMACS_CONFIGURATION get_emacs_configuration ()
473 #define EMACS_CONFIG_OPTIONS get_emacs_configuration_options ()
474 #endif
475
476
477
478
479 #define _WINSOCKAPI_ 1
480 #if !(defined __MINGW32_VERSION && __MINGW32_VERSION >= 5000002L)
481
482
483
484 # define _WINSOCK_H
485 #endif
486
487
488 #include <stdlib.h>
489 #include <sys/stat.h>
490 #ifdef _MSC_VER
491 #define alloca _alloca
492 #else
493 #include <malloc.h>
494 #endif
495
496
497
498 #undef mkdir
499 #define mkdir(d,f) sys_mkdir(d,f)
500 int sys_mkdir (const char *, mode_t);
501
502 #ifdef emacs
503
504 typedef void * (* malloc_fn)(size_t);
505 typedef void * (* realloc_fn)(void *, size_t);
506 typedef void (* free_fn)(void *);
507
508 extern void *malloc_before_dump(size_t);
509 extern void *realloc_before_dump(void *, size_t);
510 extern void free_before_dump(void *);
511 extern void *malloc_after_dump(size_t);
512 extern void *realloc_after_dump(void *, size_t);
513 extern void free_after_dump(void *);
514
515 extern void *malloc_after_dump_9x(size_t);
516 extern void *realloc_after_dump_9x(void *, size_t);
517 extern void free_after_dump_9x(void *);
518
519 extern void *sys_calloc(size_t, size_t);
520
521 extern malloc_fn the_malloc_fn;
522 extern realloc_fn the_realloc_fn;
523 extern free_fn the_free_fn;
524
525 #define malloc(size) (*the_malloc_fn)(size)
526 #define free(ptr) (*the_free_fn)(ptr)
527 #define realloc(ptr, size) (*the_realloc_fn)(ptr, size)
528 #define calloc(num, size) sys_calloc(num, size)
529
530 #endif
531
532
533 #ifndef NULL
534 #ifdef __cplusplus
535 #define NULL 0
536 #else
537 #define NULL ((void *)0)
538 #endif
539 #endif
540
541
542 #ifndef sys_nerr
543 #define sys_nerr _sys_nerr
544 #endif
545
546
547 #ifdef putenv
548 # undef putenv
549 #endif
550 #define putenv sys_putenv
551 extern int sys_putenv (char *);
552
553 extern int getloadavg (double *, int);
554 extern int getpagesize (void);
555
556 extern void * memrchr (void const *, int, size_t);
557
558
559 extern int mkostemp (char *, int);
560
561 #if defined (__MINGW32__)
562
563
564 # ifndef HAVE_LONG_LONG_INT
565 # define HAVE_LONG_LONG_INT 1
566 # endif
567
568
569 # ifndef HAVE_UNSIGNED_LONG_LONG_INT
570 # define HAVE_UNSIGNED_LONG_LONG_INT 1
571 # endif
572
573 #endif
574
575 #ifdef _MSC_VER
576 # if defined(_WIN64)
577 typedef __int64 EMACS_INT;
578 typedef unsigned __int64 EMACS_UINT;
579 # define EMACS_INT_MAX LLONG_MAX
580 # define PRIuMAX "llu"
581 # define pI "ll"
582
583 # define _INTPTR 2
584 # elif defined(_WIN32)
585
586
587
588 # ifdef WIDE_EMACS_INT
589
590
591 typedef __int64 EMACS_INT;
592 typedef unsigned __int64 EMACS_UINT;
593 # define EMACS_INT_MAX LLONG_MAX
594 # define PRIuMAX "llu"
595 # define pI "I64"
596 # else
597 typedef int EMACS_INT;
598 typedef unsigned int EMACS_UINT;
599 # define EMACS_INT_MAX LONG_MAX
600 # define PRIuMAX "lu"
601 # define pI "l"
602 # endif
603 # endif
604 #endif
605
606
607 #define SYSTEM_PURESIZE_EXTRA 50000
608
609 #define DATA_START get_data_start ()
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628 #ifdef _MSC_VER
629 #pragma data_seg("EMDATA")
630 #pragma bss_seg("EMBSS")
631 #endif
632
633
634
635
636 #ifdef _MSC_VER
637 #if _MSC_VER >= 800 && !defined(__cplusplus)
638
639
640
641 #pragma warning(disable:4116)
642
643
644
645 #pragma warning(disable:4244)
646
647
648
649 #pragma warning(disable:4308)
650 #endif
651 #endif
652
653
654 #define W32_DAEMON_EVENT "EmacsServerEvent"
655
656