diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-04-19 14:15:30 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-04-19 15:50:45 -0400 |
commit | 6cdb407aa23d8b129e9b9a49a4528c3e0def69e6 (patch) | |
tree | b32a4862101e4144eaff83e3baeabbb98aedabba /config | |
parent | 71f822ec2bf8c41f782f154d87b7b415a530dd03 (diff) | |
download | bfs-6cdb407aa23d8b129e9b9a49a4528c3e0def69e6.tar.xz |
config: Check for strerror_[lr]()
Diffstat (limited to 'config')
-rw-r--r-- | config/header.mk | 6 | ||||
-rw-r--r-- | config/strerror-l.c | 11 | ||||
-rw-r--r-- | config/strerror-r-gnu.c | 11 | ||||
-rw-r--r-- | config/strerror-r-posix.c | 11 | ||||
-rw-r--r-- | config/uselocale.c | 9 |
5 files changed, 47 insertions, 1 deletions
diff --git a/config/header.mk b/config/header.mk index 55657f8..36ad98e 100644 --- a/config/header.mk +++ b/config/header.mk @@ -20,7 +20,11 @@ HEADERS := \ ${GEN}/posix-spawn-addfchdir.h \ ${GEN}/posix-spawn-addfchdir-np.h \ ${GEN}/statx.h \ - ${GEN}/statx-syscall.h + ${GEN}/statx-syscall.h \ + ${GEN}/strerror-l.h \ + ${GEN}/strerror-r-gnu.h \ + ${GEN}/strerror-r-posix.h \ + ${GEN}/uselocale.h ${GEN}/config.h: ${HEADERS} ${MSG} "[ GEN] ${TGT}" diff --git a/config/strerror-l.c b/config/strerror-l.c new file mode 100644 index 0000000..3dcc4d7 --- /dev/null +++ b/config/strerror-l.c @@ -0,0 +1,11 @@ +// Copyright © Tavian Barnes <tavianator@tavianator.com> +// SPDX-License-Identifier: 0BSD + +#include <errno.h> +#include <locale.h> +#include <string.h> + +int main(void) { + locale_t locale = duplocale(LC_GLOBAL_LOCALE); + return !strerror_l(ENOMEM, locale); +} diff --git a/config/strerror-r-gnu.c b/config/strerror-r-gnu.c new file mode 100644 index 0000000..26ca0ee --- /dev/null +++ b/config/strerror-r-gnu.c @@ -0,0 +1,11 @@ +// Copyright © Tavian Barnes <tavianator@tavianator.com> +// SPDX-License-Identifier: 0BSD + +#include <errno.h> +#include <string.h> + +int main(void) { + char buf[256]; + // Check that strerror_r() returns a pointer + return *strerror_r(ENOMEM, buf, sizeof(buf)); +} diff --git a/config/strerror-r-posix.c b/config/strerror-r-posix.c new file mode 100644 index 0000000..41b2d30 --- /dev/null +++ b/config/strerror-r-posix.c @@ -0,0 +1,11 @@ +// Copyright © Tavian Barnes <tavianator@tavianator.com> +// SPDX-License-Identifier: 0BSD + +#include <errno.h> +#include <string.h> + +int main(void) { + char buf[256]; + // Check that strerror_r() returns an integer + return 2 * strerror_r(ENOMEM, buf, sizeof(buf)); +} diff --git a/config/uselocale.c b/config/uselocale.c new file mode 100644 index 0000000..a712ff8 --- /dev/null +++ b/config/uselocale.c @@ -0,0 +1,9 @@ +// Copyright © Tavian Barnes <tavianator@tavianator.com> +// SPDX-License-Identifier: 0BSD + +#include <locale.h> + +int main(void) { + locale_t locale = uselocale((locale_t)0); + return locale == LC_GLOBAL_LOCALE; +} |