Skip to content

Commit

Permalink
build: use feature probes for CLOEXEC (#4206)
Browse files Browse the repository at this point in the history
  • Loading branch information
camshaft authored Sep 19, 2023
1 parent 1640db5 commit 9d1e6c8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
20 changes: 20 additions & 0 deletions tests/features/S2N_CLOEXEC_SUPPORTED.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

#include <fcntl.h>

int main() {
return O_CLOEXEC;
}
1 change: 1 addition & 0 deletions tests/features/S2N_CLOEXEC_SUPPORTED.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Werror
22 changes: 22 additions & 0 deletions tests/features/S2N_CLOEXEC_XOPEN_SUPPORTED.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

#define _XOPEN_SOURCE 700
#include <fcntl.h>
#undef _XOPEN_SOURCE

int main() {
return O_CLOEXEC;
}
1 change: 1 addition & 0 deletions tests/features/S2N_CLOEXEC_XOPEN_SUPPORTED.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Werror
8 changes: 6 additions & 2 deletions utils/s2n_random.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@
* 700. In glibc 2.11 and earlier, one obtains the definitions by
* defining _GNU_SOURCE.
*
* # Relavent Links
* We use two feature probes to detect the need to perform this workaround.
* It is only applied if we can't get CLOEXEC without it and the build doesn't
* fail with _XOPEN_SOURCE being defined.
*
* # Relevent Links
*
* - POSIX.1-2017: https://pubs.opengroup.org/onlinepubs/9699919799
* - https://stackoverflow.com/a/5724485
* - https://stackoverflow.com/a/5583764
*/
#ifndef _XOPEN_SOURCE
#if !defined(S2N_CLOEXEC_SUPPORTED) && defined(S2N_CLOEXEC_XOPEN_SUPPORTED) && !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 700
#include <fcntl.h>
#undef _XOPEN_SOURCE
Expand Down

0 comments on commit 9d1e6c8

Please sign in to comment.