Skip to content

Commit

Permalink
strdup is not C99 (#2008)
Browse files Browse the repository at this point in the history
### Issues:
Addresses:
* aws/aws-lc-rs#610

### Description of changes: 
`strdup` was only officially [added to libc in
C23](https://en.cppreference.com/w/c/string/byte/strdup). Platforms we
support may require the `__STDC_WANT_LIB_EXT2__` or `_POSIX_C_SOURCE`
macros to be defined prior to the inclusion of the "string.h" header.

### Call-outs:
* Reference: https://en.cppreference.com/w/c/experimental/dynamic/strdup


By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.
  • Loading branch information
justsmth authored Dec 4, 2024
1 parent 7c47081 commit 905e9d0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crypto/err/err.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@
* ([email protected]). This product includes software written by Tim
* Hudson ([email protected]). */

// `strdup` was only officially added in C23:
// * https://en.cppreference.com/w/c/string/byte/strdup
// The following macros are needed to ensure its definition
// is provided by the headers.
#ifdef __STDC_ALLOC_LIB__
#define __STDC_WANT_LIB_EXT2__ 1
#else
#define _POSIX_C_SOURCE 200809L
#endif

// Ensure we can't call OPENSSL_malloc circularly.
#define _BORINGSSL_PROHIBIT_OPENSSL_MALLOC
#include <openssl/err.h>
Expand Down

0 comments on commit 905e9d0

Please sign in to comment.