diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -318,6 +318,8 @@ .. dynamicpie .. + errno + .. static .. .. diff --git a/lib/csu/tests/Makefile b/lib/csu/tests/Makefile --- a/lib/csu/tests/Makefile +++ b/lib/csu/tests/Makefile @@ -4,6 +4,7 @@ TESTS_SUBDIRS= dynamic TESTS_SUBDIRS+= dynamiclib TESTS_SUBDIRS+= dynamicpie +TESTS_SUBDIRS+= errno TESTS_SUBDIRS+= static SUBDIR_DEPEND_dynamiclib=dso diff --git a/lib/csu/tests/errno/Makefile b/lib/csu/tests/errno/Makefile new file mode 100644 --- /dev/null +++ b/lib/csu/tests/errno/Makefile @@ -0,0 +1,18 @@ +PLAIN_TESTS_C= errno_test \ + errno_static_test \ + errno_thr_test \ + errno_thr_static_test + +SRCS.errno_static_test= errno_test.c +LDFLAGS.errno_static_test= -static + +SRCS.errno_thr_test= errno_test.c +LIBADD.errno_thr_test= pthread + +SRCS.errno_thr_static_test= errno_test.c +LDFLAGS.errno_thr_static_test= -static +LIBADD.errno_thr_static_test= pthread + +MK_PIE:= no + +.include diff --git a/lib/csu/tests/errno/errno_test.c b/lib/csu/tests/errno/errno_test.c new file mode 100644 --- /dev/null +++ b/lib/csu/tests/errno/errno_test.c @@ -0,0 +1,23 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2025 Mark Johnston + */ + +#include +#include + +static void __attribute__((constructor)) +f(void) +{ + errno = 42; +} + +int +main(void) +{ + /* errno must be zero upon program startup. */ + if (errno != 0) + exit(1); + exit(0); +}