/* Common definitions.
- Copyright (C) 1986-2015 Free Software Foundation, Inc.
+ Copyright (C) 1986-2019 Free Software Foundation, Inc.
This file is part of GDB.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#ifndef COMMON_DEFS_H
-#define COMMON_DEFS_H
+#ifndef COMMON_COMMON_DEFS_H
+#define COMMON_COMMON_DEFS_H
#include "config.h"
+
+#undef PACKAGE_NAME
+#undef PACKAGE_VERSION
+#undef PACKAGE_STRING
+#undef PACKAGE_TARNAME
+
#ifdef GDBSERVER
#include "build-gnulib-gdbserver/config.h"
#else
-#include "build-gnulib/config.h"
+#include "../../gnulib/config.h"
#endif
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
+#undef PACKAGE_NAME
+#undef PACKAGE_VERSION
+#undef PACKAGE_STRING
+#undef PACKAGE_TARNAME
/* From:
https://www.gnu.org/software/gnulib/manual/html_node/stdint_002eh.html
"On some hosts that predate C++11, when using C++ one must define
__STDC_CONSTANT_MACROS to make visible the definitions of constant
macros such as INTMAX_C, and one must define __STDC_LIMIT_MACROS to
- make visible the definitions of limit macros such as INTMAX_MAX."
+ make visible the definitions of limit macros such as INTMAX_MAX.".
- gnulib doesn't fix this for us correctly yet. See:
- https://lists.gnu.org/archive/html/bug-gnulib/2015-11/msg00004.html
+ And:
+ https://www.gnu.org/software/gnulib/manual/html_node/inttypes_002eh.html
- Meanwhile, explicitly define these ourselves, as C99 intended. */
+ "On some hosts that predate C++11, when using C++ one must define
+ __STDC_FORMAT_MACROS to make visible the declarations of format
+ macros such as PRIdMAX."
+
+ Must do this before including any system header, since other system
+ headers may include stdint.h/inttypes.h. */
#define __STDC_CONSTANT_MACROS 1
#define __STDC_LIMIT_MACROS 1
-#include <stdint.h>
+#define __STDC_FORMAT_MACROS 1
+
+/* Some distros enable _FORTIFY_SOURCE by default, which on occasion
+ has caused build failures with -Wunused-result when a patch is
+ developed on a distro that does not enable _FORTIFY_SOURCE. We
+ enable it here in order to try to catch these problems earlier;
+ plus this seems like a reasonable safety measure. The check for
+ optimization is required because _FORTIFY_SOURCE only works when
+ optimization is enabled. If _FORTIFY_SOURCE is already defined,
+ then we don't do anything. */
+
+#if !defined _FORTIFY_SOURCE && defined __OPTIMIZE__ && __OPTIMIZE__ > 0
+#define _FORTIFY_SOURCE 2
+#endif
+/* We don't support Windows versions before XP, so we define
+ _WIN32_WINNT correspondingly to ensure the Windows API headers
+ expose the required symbols. */
+#if defined (__MINGW32__) || defined (__CYGWIN__)
+# ifdef _WIN32_WINNT
+# if _WIN32_WINNT < 0x0501
+# undef _WIN32_WINNT
+# define _WIN32_WINNT 0x0501
+# endif
+# else
+# define _WIN32_WINNT 0x0501
+# endif
+#endif /* __MINGW32__ || __CYGWIN__ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <stdint.h>
#include <string.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h> /* for strcasecmp and strncasecmp */
+#endif
#include <errno.h>
#include <alloca.h>
#undef ATTRIBUTE_PRINTF
#define ATTRIBUTE_PRINTF _GL_ATTRIBUTE_FORMAT_PRINTF
+#if GCC_VERSION >= 3004
+#define ATTRIBUTE_UNUSED_RESULT __attribute__ ((__warn_unused_result__))
+#else
+#define ATTRIBUTE_UNUSED_RESULT
+#endif
+
#include "libiberty.h"
#include "pathmax.h"
#include "gdb/signals.h"
#include "common-debug.h"
#include "cleanups.h"
#include "common-exceptions.h"
+#include "common/poison.h"
-#ifdef __cplusplus
-# define EXTERN_C extern "C"
-# define EXTERN_C_PUSH extern "C" {
-# define EXTERN_C_POP }
-#else
-# define EXTERN_C extern
-# define EXTERN_C_PUSH
-# define EXTERN_C_POP
+#define EXTERN_C extern "C"
+#define EXTERN_C_PUSH extern "C" {
+#define EXTERN_C_POP }
+
+/* Pull in gdb::unique_xmalloc_ptr. */
+#include "common/gdb_unique_ptr.h"
+
+/* String containing the current directory (what getwd would return). */
+extern char *current_directory;
+
+/* sbrk on macOS is not useful for our purposes, since sbrk(0) always
+ returns the same value. brk/sbrk on macOS is just an emulation
+ that always returns a pointer to a 4MB section reserved for
+ that. */
+
+#if defined (HAVE_SBRK) && !__APPLE__
+#define HAVE_USEFUL_SBRK 1
#endif
-#endif /* COMMON_DEFS_H */
+#endif /* COMMON_COMMON_DEFS_H */