Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow builds with -std=c99 on LTS branch 2.7 #3656

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog.d/c99.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Features
* Allow builds with -std=c99. Contributed in #3656.
5 changes: 5 additions & 0 deletions library/entropy_poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
* **********
*/

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As reported in #3432, _GNU_SOURCE should not be redefined if it's already defined.

This also applies to _POSIX_C_SOURCE, _XOPEN_SOURCE and any similar macro.

#endif

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
Expand Down
6 changes: 6 additions & 0 deletions library/net_sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
* **********
*/

/* 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
#define _XOPEN_SOURCE 600 /* sockaddr_storage */

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
Expand Down
5 changes: 5 additions & 0 deletions programs/aes/aescrypt2.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
* **********
*/

/* 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 200112L

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
Expand Down
5 changes: 5 additions & 0 deletions programs/aes/crypt_and_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
* **********
*/

/* 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 200112L

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
Expand Down
6 changes: 6 additions & 0 deletions programs/ssl/ssl_mail_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
* **********
*/

/* Enable definition of gethostname() 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
#define _XOPEN_SOURCE 600

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
Expand Down
13 changes: 13 additions & 0 deletions tests/scripts/generate_code.pl
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,19 @@
*
*/

#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
#define _POSIX_C_SOURCE 200112L // for fileno() from <stdio.h>
#endif

/*
* for arc4random_buf() from <stdlib.h>
*/
#if defined(__NetBSD__)
#define _NETBSD_SOURCE 1
#elif defined(__OpenBSD__)
#define _BSD_SOURCE 1
#endif

#if !defined(MBEDTLS_CONFIG_FILE)
#include <mbedtls/config.h>
#else
Expand Down
1 change: 1 addition & 0 deletions tests/suites/helpers.function
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ typedef UINT32 uint32_t;

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

/*
Expand Down
8 changes: 6 additions & 2 deletions tests/suites/main_test.function
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ int main(int argc, const char *argv[])
/* Other Local variables */
int arg_index = 1;
const char *next_arg;
size_t testfile_index, i, cnt;
size_t testfile_index, i, cnt, len;
int ret;
unsigned total_errors = 0, total_tests = 0, total_skipped = 0;
FILE *file;
Expand Down Expand Up @@ -400,14 +400,18 @@ int main(int argc, const char *argv[])
{
if( 0 != option_verbose )
{
len = strlen( params[i] );
unmet_dependencies[unmet_dep_count] =
strdup( params[i] );
malloc( len + 1 );
if( unmet_dependencies[unmet_dep_count] == NULL )
{
mbedtls_fprintf( stderr,
"FATAL: Out of memory\n" );
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
}
strncpy( unmet_dependencies[unmet_dep_count],
params[i], len );
unmet_dependencies[unmet_dep_count][len] = '\0';
}
unmet_dep_count++;
}
Expand Down