Use the Autoconf macro AC_USE_SYSTEM_EXTENSIONS

The Autoconf macro AC_USE_SYSTEM_EXTENSIONS defines preprocessor macros
which turn on extensions to C and POSIX. The macro also makes it easier
for developers to use the extensions without needing (or forgetting) to
define them manually.

The macro can be safely used because it was introduced in Autoconf 2.60
and Tor requires Autoconf 2.63 and above.
This commit is contained in:
cypherpunks 2016-06-17 13:43:25 +00:00 committed by Nick Mathewson
parent 9a63f059b9
commit 94762e37b9
12 changed files with 7 additions and 44 deletions

3
changes/bug19139 Normal file
View File

@ -0,0 +1,3 @@
o Minor features (build):
- Use the Autoconf macro AC_USE_SYSTEM_EXTENSIONS to automatically
turn on C and POSIX extensions. Closes ticket 19139.

View File

@ -16,6 +16,7 @@ AM_INIT_AUTOMAKE([foreign 1.11 subdir-objects])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
AC_CONFIG_HEADERS([orconfig.h]) AC_CONFIG_HEADERS([orconfig.h])
AC_USE_SYSTEM_EXTENSIONS
AC_CANONICAL_HOST AC_CANONICAL_HOST
PKG_PROG_PKG_CONFIG PKG_PROG_PKG_CONFIG
@ -1552,9 +1553,6 @@ int main(int c, char **v) { puts(__FUNCTION__); }])],
AC_CACHE_CHECK([whether we have extern char **environ already declared], AC_CACHE_CHECK([whether we have extern char **environ already declared],
tor_cv_have_environ_declared, tor_cv_have_environ_declared,
AC_COMPILE_IFELSE([AC_LANG_SOURCE([ AC_COMPILE_IFELSE([AC_LANG_SOURCE([
/* We define _GNU_SOURCE here because it is also defined in compat.c.
* Without it environ doesn't get declared. */
#define _GNU_SOURCE
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif

View File

@ -79,24 +79,21 @@ AC_DEFUN([AC_PC_FROM_UCONTEXT],
if ! $pc_field_found; then if ! $pc_field_found; then
# Prefer sys/ucontext.h to ucontext.h, for OS X's sake. # Prefer sys/ucontext.h to ucontext.h, for OS X's sake.
if test "x$ac_cv_header_cygwin_signal_h" = xyes; then if test "x$ac_cv_header_cygwin_signal_h" = xyes; then
AC_TRY_COMPILE([#define _GNU_SOURCE 1 AC_TRY_COMPILE([#include <cygwin/signal.h>],
#include <cygwin/signal.h>],
[ucontext_t u; return u.$pc_field == 0;], [ucontext_t u; return u.$pc_field == 0;],
AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field, AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
How to access the PC from a struct ucontext) How to access the PC from a struct ucontext)
AC_MSG_RESULT([$pc_field]) AC_MSG_RESULT([$pc_field])
pc_field_found=true) pc_field_found=true)
elif test "x$ac_cv_header_sys_ucontext_h" = xyes; then elif test "x$ac_cv_header_sys_ucontext_h" = xyes; then
AC_TRY_COMPILE([#define _GNU_SOURCE 1 AC_TRY_COMPILE([#include <sys/ucontext.h>],
#include <sys/ucontext.h>],
[ucontext_t u; return u.$pc_field == 0;], [ucontext_t u; return u.$pc_field == 0;],
AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field, AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
How to access the PC from a struct ucontext) How to access the PC from a struct ucontext)
AC_MSG_RESULT([$pc_field]) AC_MSG_RESULT([$pc_field])
pc_field_found=true) pc_field_found=true)
elif test "x$ac_cv_header_ucontext_h" = xyes; then elif test "x$ac_cv_header_ucontext_h" = xyes; then
AC_TRY_COMPILE([#define _GNU_SOURCE 1 AC_TRY_COMPILE([#include <ucontext.h>],
#include <ucontext.h>],
[ucontext_t u; return u.$pc_field == 0;], [ucontext_t u; return u.$pc_field == 0;],
AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field, AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
How to access the PC from a struct ucontext) How to access the PC from a struct ucontext)

View File

@ -13,9 +13,6 @@
* detect crashes. * detect crashes.
*/ */
#define __USE_GNU
#define _GNU_SOURCE 1
#include "orconfig.h" #include "orconfig.h"
#include "compat.h" #include "compat.h"
#include "util.h" #include "util.h"

View File

@ -12,18 +12,6 @@
* the platform. * the platform.
**/ **/
/* This is required on rh7 to make strptime not complain.
* We also need it to make memmem get defined (where available)
*/
/* XXXX We should just use AC_USE_SYSTEM_EXTENSIONS in our autoconf,
* and get this (and other important stuff!) automatically. Once we do that,
* make sure to also change the extern char **environ detection in
* configure.ac, because whether that is declared or not depends on whether
* we have _GNU_SOURCE defined! Maybe that means that once we take this out,
* we can also take out the configure check. */
#define _GNU_SOURCE
#define COMPAT_PRIVATE #define COMPAT_PRIVATE
#include "compat.h" #include "compat.h"

View File

@ -10,8 +10,6 @@
* functions. * functions.
*/ */
#define _GNU_SOURCE
#include "orconfig.h" #include "orconfig.h"
#include <pthread.h> #include <pthread.h>
#include <signal.h> #include <signal.h>

View File

@ -11,8 +11,6 @@
* modules.) * modules.)
*/ */
#define _GNU_SOURCE
#include "orconfig.h" #include "orconfig.h"
#include <stdlib.h> #include <stdlib.h>
#include "compat.h" #include "compat.h"

View File

@ -56,7 +56,6 @@ ENABLE_GCC_WARNING(redundant-decls)
#include <ctype.h> #include <ctype.h>
#endif #endif
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#define _GNU_SOURCE
#include <unistd.h> #include <unistd.h>
#endif #endif
#ifdef HAVE_FCNTL_H #ifdef HAVE_FCNTL_H

View File

@ -39,8 +39,6 @@
#if defined(USE_LIBSECCOMP) #if defined(USE_LIBSECCOMP)
#define _GNU_SOURCE
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#include <sys/types.h> #include <sys/types.h>

View File

@ -39,12 +39,6 @@ typedef struct sandbox_cfg_elem sandbox_cfg_t;
*/ */
#ifdef USE_LIBSECCOMP #ifdef USE_LIBSECCOMP
#ifndef __USE_GNU
#define __USE_GNU
#endif
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <sys/ucontext.h> #include <sys/ucontext.h>
#include <seccomp.h> #include <seccomp.h>
#include <netdb.h> #include <netdb.h>

View File

@ -9,10 +9,6 @@
* process control. * process control.
**/ **/
/* This is required on rh7 to make strptime not complain.
*/
#define _GNU_SOURCE
#include "orconfig.h" #include "orconfig.h"
#ifdef HAVE_FCNTL_H #ifdef HAVE_FCNTL_H
#include <fcntl.h> #include <fcntl.h>

View File

@ -50,9 +50,6 @@
#endif #endif
#endif #endif
/* #define _POSIX_C_SOURCE 200507 */
#define _GNU_SOURCE
#ifdef DNS_USE_CPU_CLOCK_FOR_ID #ifdef DNS_USE_CPU_CLOCK_FOR_ID
#ifdef DNS_USE_OPENSSL_FOR_ID #ifdef DNS_USE_OPENSSL_FOR_ID
#error Multiple id options selected #error Multiple id options selected