Skip to content

Commit

Permalink
Fix build using -std=c99
Browse files Browse the repository at this point in the history
In each place where POSIX/GNU functions are used, the file must declare
that it wants POSIX functionality before including any system headers.
  • Loading branch information
NWilson committed Jun 25, 2018
1 parent 512b4ee commit 2682edf
Showing 9 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ Changes
* Allow overriding the time on Windows via the platform-time abstraction.
Fixed by Nick Wilson.
* Use gmtime_r/gmtime_s for thread-safety. Fixed by Nick Wilson.
* Fix build using -std=c99. Fixed by Nick Wilson.

= mbed TLS 2.11.0 branch released 2018-06-18

5 changes: 5 additions & 0 deletions library/entropy_poll.c
Original file line number Diff line number Diff line change
@@ -19,6 +19,11 @@
* This file is part of mbed TLS (https://tls.mbed.org)
*/

#if defined(__linux__)
/* Ensure that syscall() is available even when compiling with -std=c99 */
#define _GNU_SOURCE
#endif

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
5 changes: 5 additions & 0 deletions library/net_sockets.c
Original file line number Diff line number Diff line change
@@ -19,6 +19,11 @@
* This file is part of mbed TLS (https://tls.mbed.org)
*/

/* Enable definition of getaddrinfo() even when compiling with -std=c99. Must
* be set before config.h, which pulls in glibc's features.h indirectly.
* Harmless on other platforms. */
#define _POSIX_C_SOURCE 200112L

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
4 changes: 4 additions & 0 deletions library/x509.c
Original file line number Diff line number Diff line change
@@ -29,6 +29,10 @@
* http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
*/

/* Ensure gmtime_r is available even with -std=c99; must be included before
* config.h, which pulls in glibc's features.h. Harmless on other platforms. */
#define _XOPEN_SOURCE 500

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
5 changes: 5 additions & 0 deletions programs/aes/aescrypt2.c
Original file line number Diff line number Diff line change
@@ -19,6 +19,11 @@
* This file is part of mbed TLS (https://tls.mbed.org)
*/

/* Enable definition of fileno() even when compiling with -std=c99. Must be
* set before config.h, which pulls in glibc's features.h indirectly.
* Harmless on other platforms. */
#define _POSIX_C_SOURCE 1

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
5 changes: 5 additions & 0 deletions programs/aes/crypt_and_hash.c
Original file line number Diff line number Diff line change
@@ -20,6 +20,11 @@
* This file is part of mbed TLS (https://tls.mbed.org)
*/

/* Enable definition of fileno() even when compiling with -std=c99. Must be
* set before config.h, which pulls in glibc's features.h indirectly.
* Harmless on other platforms. */
#define _POSIX_C_SOURCE 1

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
5 changes: 5 additions & 0 deletions programs/ssl/ssl_mail_client.c
Original file line number Diff line number Diff line change
@@ -19,6 +19,11 @@
* This file is part of mbed TLS (https://tls.mbed.org)
*/

/* Enable definition of hostname() even when compiling with -std=c99. Must be
* set before config.h, which pulls in glibc's features.h indirectly.
* Harmless on other platforms. */
#define _POSIX_C_SOURCE 200112L

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -15,6 +15,11 @@ if(NOT PERL_FOUND)
message(FATAL_ERROR "Cannot build test suites without Perl")
endif()

# Enable definition of various functions used throughout the testsuite
# (hostname, strdup, fileno...) even when compiling with -std=c99. Harmless
# on non-POSIX platforms.
add_definitions("-D_POSIX_C_SOURCE=200809L")

function(add_test_suite suite_name)
if(ARGV1)
set(data_name ${ARGV1})
1 change: 1 addition & 0 deletions tests/suites/helpers.function
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ typedef UINT32 uint32_t;

#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
#include <unistd.h>
#include <strings.h>
#endif

/*----------------------------------------------------------------------------*/

0 comments on commit 2682edf

Please sign in to comment.