Added nt/gnulib.mk and removed kludges from ms-w32.h and ntlib.h.
[bpt/emacs.git] / nt / inc / ms-w32.h
index aab3039..6fca448 100644 (file)
@@ -1,6 +1,6 @@
 /* System description file for Windows NT.
 
-Copyright (C) 1993-1995, 2001-201 Free Software Foundation, Inc.
+Copyright (C) 1993-1995, 2001-2013 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -67,9 +67,23 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #endif
 
 #if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
-#define HAVE___BUILTIN_UNWIND_INIT 1
+# ifndef HAVE___BUILTIN_UNWIND_INIT
+#  define HAVE___BUILTIN_UNWIND_INIT 1
+# endif
 #endif
 
+/* This isn't perfect, as some systems might have the page file in
+   another place.  Also, I suspect that the time stamp of that file
+   might also change when Windows enlarges the file due to
+   insufficient VM.  Still, this seems to be the most reliable way;
+   the alternative (of using GetSystemTimes) won't work on laptops
+   that hibernate, because the system clock is stopped then.  Other
+   possibility would be to run "net statistics workstation" and parse
+   the output, but that's gross.  So this should do; if the file is
+   not there, the boot time will be returned as zero, and filelock.c
+   already handles that.  */
+#define BOOT_TIME_FILE "C:/pagefile.sys"
+
 /* ============================================================ */
 
 /* Here, add any special hacks needed to make Emacs work on this
@@ -87,8 +101,12 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #endif
 
 #ifdef __GNUC__
-# define restrict __restrict__
+/* config.h may have defined already.  */
+# ifndef restrict
+#  define restrict __restrict__
+# endif
 #else
+  /* FIXME: should we define to __restrict, which MSVC supports? */
 # define restrict
 #endif
 
@@ -115,6 +133,17 @@ typedef unsigned short mode_t;
 extern char *getenv ();
 #endif
 
+/* Prevent accidental use of features unavailable in older Windows
+   versions we still support.  MinGW64 defines this to a higher value
+   in its system headers, and is not really compatible with values
+   lower than 0x0500, so leave it alone.  */
+#ifndef _W64
+# define _WIN32_WINNT 0x0400
+#endif
+
+/* Make a leaner executable.  */
+#define WIN32_LEAN_AND_MEAN 1
+
 #ifdef HAVE_STRINGS_H
 #include "strings.h"
 #endif
@@ -125,14 +154,33 @@ extern char *getenv ();
 #endif
 
 #ifdef HAVE_NTGUI
-#define HAVE_WINDOW_SYSTEM 1
-#define HAVE_MENUS 1
+# ifndef HAVE_WINDOW_SYSTEM
+#  define HAVE_WINDOW_SYSTEM 1
+# endif
+# ifndef HAVE_MENUS
+#  define HAVE_MENUS 1
+# endif
 #endif
 
 /* Get some redefinitions in place.  */
 
 #ifdef emacs
 
+#ifdef _W64
+/* MinGW64 specific stuff.  */
+/* Make sure 'struct timespec' and 'struct timezone' are defined.  */
+#include <sys/types.h>
+#include <time.h>
+/* This prototype avoids MinGW64 compiler warnings due to the fact
+   that time.h is included before localtime is redirected to
+   sys_localtime below.  */
+extern struct tm * sys_localtime (const time_t *);
+/* MinGW64 uses a 2-argument _setjmp, and setjmp is a macro defined to
+   supply the 2nd arg correctly, so don't use _setjmp directly in that
+   case. */
+#undef HAVE__SETJMP
+#endif
+
 #ifdef _MSC_VER
 #include <sys/timeb.h>
 #include <sys/stat.h>
@@ -149,7 +197,6 @@ extern char *getenv ();
 #define chdir   sys_chdir
 #undef chmod
 #define chmod   sys_chmod
-#define chown   sys_chown
 #undef close
 #define close   sys_close
 #undef creat
@@ -209,6 +256,7 @@ extern int sys_unlink (const char *);
 /* Map to MSVC names.  */
 #define execlp    _execlp
 #define execvp    _execvp
+#define fdatasync _commit
 #define fdopen   _fdopen
 #ifndef fileno
 #define fileno   _fileno
@@ -220,17 +268,14 @@ extern int sys_unlink (const char *);
 typedef int pid_t;
 #define snprintf  _snprintf
 #define strtoll   _strtoi64
+#define copysign  _copysign
 #endif
 #define isatty    _isatty
-#define logb      _logb
 #define _longjmp  longjmp
 #define lseek     _lseek
 #define popen     _popen
 #define pclose    _pclose
 #define umask    _umask
-#ifndef _MSC_VER
-#define utimbuf          _utimbuf
-#endif
 #define strdup    _strdup
 #define strupr    _strupr
 #define strnicmp  _strnicmp
@@ -247,26 +292,28 @@ int _getpid (void);
    array, and triggers an error message.  */
 #include <time.h>
 #define tzname    _tzname
-#if !defined (_MSC_VER) || (_MSC_VER < 1400)
-#undef  utime
-#define utime    _utime
-#endif
 
 /* 'struct timespec' is used by time-related functions in lib/ and
    elsewhere, but we don't use lib/time.h where the structure is
    defined.  */
+/* MinGW64 defines 'struct timespec' and _TIMESPEC_DEFINED in sys/types.h.  */
+#ifndef _TIMESPEC_DEFINED
 struct timespec
 {
   time_t       tv_sec;         /* seconds */
   long int     tv_nsec;        /* nanoseconds */
 };
+#endif
 
 /* Required for functions in lib/time_r.c, since we don't use lib/time.h.  */
 extern struct tm *gmtime_r (time_t const * restrict, struct tm * restrict);
 extern struct tm *localtime_r (time_t const * restrict, struct tm * restrict);
 
+#ifdef _MSC_VER
 /* This is hacky, but is necessary to avoid warnings about macro
-   redefinitions using the SDK compilers.  */
+   redefinitions using the MSVC compilers, since, when __STDC__ is
+   undefined or zero, those compilers declare functions like fileno,
+   lseek, and chdir, for which we defined macros above.  */
 #ifndef __STDC__
 #define __STDC__ 1
 #define MUST_UNDEF__STDC__
@@ -278,6 +325,11 @@ extern struct tm *localtime_r (time_t const * restrict, struct tm * restrict);
 #undef __STDC__
 #undef MUST_UNDEF__STDC__
 #endif
+#else  /* !_MSC_VER */
+#include <direct.h>
+#include <io.h>
+#include <stdio.h>
+#endif /* !_MSC_VER */
 
 /* Defines that we need that aren't in the standard signal.h.  */
 #define SIGHUP  1               /* Hang up */
@@ -293,11 +345,21 @@ extern struct tm *localtime_r (time_t const * restrict, struct tm * restrict);
 #define NSIG 23
 #endif
 
+#ifndef ENOTSUP
+#define ENOTSUP ENOSYS
+#endif
+
 #ifdef _MSC_VER
 typedef int sigset_t;
 typedef int ssize_t;
 #endif
 
+#ifdef _W64    /* MinGW64 */
+#ifndef _POSIX
+typedef _sigset_t sigset_t;
+#endif
+#endif
+
 typedef void (_CALLBACK_ *signal_handler) (int);
 extern signal_handler sys_signal (int, signal_handler);
 
@@ -332,10 +394,12 @@ extern int sys_kill (int, int);
 #define getdefdir(_drv, _buf)   _getdcwd (_drv, _buf, MAXPATHLEN)
 #endif
 
+#ifndef EMACS_CONFIGURATION
 extern char *get_emacs_configuration (void);
 extern char *get_emacs_configuration_options (void);
 #define EMACS_CONFIGURATION    get_emacs_configuration ()
 #define EMACS_CONFIG_OPTIONS   get_emacs_configuration_options ()
+#endif
 
 /* Define this so that winsock.h definitions don't get included with
    windows.h.  For this to have proper effect, config.h must always be
@@ -343,13 +407,6 @@ extern char *get_emacs_configuration_options (void);
 #define _WINSOCKAPI_    1
 #define _WINSOCK_H
 
-/* Prevent accidental use of features unavailable in
-   older Windows versions we still support.  */
-#define _WIN32_WINNT 0x0400
-
-/* Make a leaner executable.  */
-#define WIN32_LEAN_AND_MEAN 1
-
 /* Defines size_t and alloca ().  */
 #ifdef emacs
 #define malloc e_malloc
@@ -390,13 +447,20 @@ extern int sys_putenv (char *);
 extern int getloadavg (double *, int);
 extern int getpagesize (void);
 
+extern void * memrchr (void const *, int, size_t);
+
+
 #if defined (__MINGW32__)
 
 /* Define to 1 if the system has the type `long long int'. */
-# define HAVE_LONG_LONG_INT 1
+# ifndef HAVE_LONG_LONG_INT
+#  define HAVE_LONG_LONG_INT 1
+# endif
 
 /* Define to 1 if the system has the type `unsigned long long int'. */
-# define HAVE_UNSIGNED_LONG_LONG_INT 1
+# ifndef HAVE_UNSIGNED_LONG_LONG_INT
+#  define HAVE_UNSIGNED_LONG_LONG_INT 1
+# endif
 
 #endif
 
@@ -484,7 +548,6 @@ extern void _DebPrint (const char *fmt, ...);
 #pragma warning(disable:4308)
 #endif
 #endif
-#define TERM_HEADER "w32term.h"
 
 
 /* ============================================================ */