aboutsummaryrefslogtreecommitdiff
path: root/contrib/netbsd-tests/lib/libc/c063
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/netbsd-tests/lib/libc/c063')
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_faccessat.c186
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_fchmodat.c198
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_fchownat.c248
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_fexecve.c95
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_fstatat.c197
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_linkat.c217
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_mkdirat.c120
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_mkfifoat.c120
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_mknodat.c151
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_o_search.c365
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_openat.c166
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_readlinkat.c158
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_renameat.c152
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_symlinkat.c150
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_unlinkat.c177
-rw-r--r--contrib/netbsd-tests/lib/libc/c063/t_utimensat.c213
16 files changed, 2913 insertions, 0 deletions
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_faccessat.c b/contrib/netbsd-tests/lib/libc/c063/t_faccessat.c
new file mode 100644
index 000000000000..5e6829f7ea45
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/c063/t_faccessat.c
@@ -0,0 +1,186 @@
+/* $NetBSD: t_faccessat.c,v 1.3 2017/01/10 15:13:56 christos Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_faccessat.c,v 1.3 2017/01/10 15:13:56 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#define DIR "dir"
+#define FILE "dir/faccessat"
+#define BASEFILE "faccessat"
+#define LINK "dir/symlink"
+#define BASELINK "symlink"
+#define FILEERR "dir/faccessaterr"
+
+ATF_TC(faccessat_fd);
+ATF_TC_HEAD(faccessat_fd, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that faccessat works with fd");
+}
+ATF_TC_BODY(faccessat_fd, tc)
+{
+ int dfd;
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(faccessat(dfd, BASEFILE, F_OK, 0) == 0);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(faccessat_fdcwd);
+ATF_TC_HEAD(faccessat_fdcwd, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that faccessat works with fd as AT_FDCWD");
+}
+ATF_TC_BODY(faccessat_fdcwd, tc)
+{
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(chdir(DIR) == 0);
+ ATF_REQUIRE(faccessat(AT_FDCWD, BASEFILE, F_OK, 0) == 0);
+}
+
+ATF_TC(faccessat_fdcwderr);
+ATF_TC_HEAD(faccessat_fdcwderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that faccessat fails with fd as AT_FDCWD and bad path");
+}
+ATF_TC_BODY(faccessat_fdcwderr, tc)
+{
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE(faccessat(AT_FDCWD, FILEERR, F_OK, 0) == -1);
+}
+
+ATF_TC(faccessat_fderr1);
+ATF_TC_HEAD(faccessat_fderr1, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that faccessat fail with bad path");
+}
+ATF_TC_BODY(faccessat_fderr1, tc)
+{
+ int dfd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(faccessat(dfd, FILEERR, F_OK, 0) == -1);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(faccessat_fderr2);
+ATF_TC_HEAD(faccessat_fderr2, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that faccessat fails with bad fdat");
+}
+ATF_TC_BODY(faccessat_fderr2, tc)
+{
+ int dfd;
+ int fd;
+ char cwd[MAXPATHLEN];
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(faccessat(dfd, BASEFILE, F_OK, 0) == -1);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(faccessat_fderr3);
+ATF_TC_HEAD(faccessat_fderr3, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that faccessat fails with fd as -1");
+}
+ATF_TC_BODY(faccessat_fderr3, tc)
+{
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(faccessat(-1, FILE, F_OK, 0) == -1);
+}
+
+ATF_TC(faccessat_fdlink);
+ATF_TC_HEAD(faccessat_fdlink, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that faccessat works on symlink");
+}
+ATF_TC_BODY(faccessat_fdlink, tc)
+{
+ int dfd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE(symlink(FILE, LINK) == 0); /* NB: FILE does not exists */
+
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+
+ ATF_REQUIRE(faccessat(dfd, BASELINK, F_OK, 0) == -1);
+ ATF_REQUIRE(errno == ENOENT);
+
+ ATF_REQUIRE(faccessat(dfd, BASELINK, F_OK, AT_SYMLINK_NOFOLLOW) == 0);
+
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, faccessat_fd);
+ ATF_TP_ADD_TC(tp, faccessat_fdcwd);
+ ATF_TP_ADD_TC(tp, faccessat_fdcwderr);
+ ATF_TP_ADD_TC(tp, faccessat_fderr1);
+ ATF_TP_ADD_TC(tp, faccessat_fderr2);
+ ATF_TP_ADD_TC(tp, faccessat_fderr3);
+ ATF_TP_ADD_TC(tp, faccessat_fdlink);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_fchmodat.c b/contrib/netbsd-tests/lib/libc/c063/t_fchmodat.c
new file mode 100644
index 000000000000..a7bb6831b86c
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/c063/t_fchmodat.c
@@ -0,0 +1,198 @@
+/* $NetBSD: t_fchmodat.c,v 1.3 2017/01/10 15:13:56 christos Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_fchmodat.c,v 1.3 2017/01/10 15:13:56 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#define DIR "dir"
+#define FILE "dir/fchmodat"
+#define BASEFILE "fchmodat"
+#define LINK "dir/symlink"
+#define BASELINK "symlink"
+#define FILEERR "dir/fchmodaterr"
+
+ATF_TC(fchmodat_fd);
+ATF_TC_HEAD(fchmodat_fd, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that fchmodat works with fd");
+}
+ATF_TC_BODY(fchmodat_fd, tc)
+{
+ int dfd;
+ int fd;
+ struct stat st;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(fchmodat(dfd, BASEFILE, 0600, 0) == 0);
+ ATF_REQUIRE(close(dfd) == 0);
+
+ ATF_REQUIRE(stat(FILE, &st) == 0);
+ ATF_REQUIRE(st.st_mode = 0600);
+}
+
+ATF_TC(fchmodat_fdcwd);
+ATF_TC_HEAD(fchmodat_fdcwd, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that fchmodat works with fd as AT_FDCWD");
+}
+ATF_TC_BODY(fchmodat_fdcwd, tc)
+{
+ int fd;
+ struct stat st;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(chdir(DIR) == 0);
+ ATF_REQUIRE(fchmodat(AT_FDCWD, BASEFILE, 0600, 0) == 0);
+
+ ATF_REQUIRE(stat(BASEFILE, &st) == 0);
+ ATF_REQUIRE(st.st_mode = 0600);
+}
+
+ATF_TC(fchmodat_fdcwderr);
+ATF_TC_HEAD(fchmodat_fdcwderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that fchmodat fails with fd as AT_FDCWD and bad path");
+}
+ATF_TC_BODY(fchmodat_fdcwderr, tc)
+{
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE(fchmodat(AT_FDCWD, FILEERR, 0600, 0) == -1);
+}
+
+ATF_TC(fchmodat_fderr1);
+ATF_TC_HEAD(fchmodat_fderr1, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that fchmodat fail with bad path");
+}
+ATF_TC_BODY(fchmodat_fderr1, tc)
+{
+ int dfd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(fchmodat(dfd, FILEERR, 0600, 0) == -1);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(fchmodat_fderr2);
+ATF_TC_HEAD(fchmodat_fderr2, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that fchmodat fails with bad fdat");
+}
+ATF_TC_BODY(fchmodat_fderr2, tc)
+{
+ int dfd;
+ int fd;
+ char cwd[MAXPATHLEN];
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(fchmodat(dfd, BASEFILE, 0600, 0) == -1);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(fchmodat_fderr3);
+ATF_TC_HEAD(fchmodat_fderr3, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that fchmodat fails with fd as -1");
+}
+ATF_TC_BODY(fchmodat_fderr3, tc)
+{
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(fchmodat(-1, FILE, 0600, 0) == -1);
+}
+
+ATF_TC(fchmodat_fdlink);
+ATF_TC_HEAD(fchmodat_fdlink, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that fchmodat works on symlink");
+}
+ATF_TC_BODY(fchmodat_fdlink, tc)
+{
+ int dfdlink;
+ struct stat st;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE(symlink(FILE, LINK) == 0);
+
+ ATF_REQUIRE((dfdlink = open(DIR, O_RDONLY, 0)) != -1);
+
+ ATF_REQUIRE(fchmodat(dfdlink, BASELINK, 0600, 0) == -1);
+ ATF_REQUIRE(errno = ENOENT);
+
+ ATF_REQUIRE(fchmodat(dfdlink, BASELINK, 0600, AT_SYMLINK_NOFOLLOW) == 0);
+
+ ATF_REQUIRE(close(dfdlink) == 0);
+
+ ATF_REQUIRE(lstat(LINK, &st) == 0);
+ ATF_REQUIRE(st.st_mode = 0600);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, fchmodat_fd);
+ ATF_TP_ADD_TC(tp, fchmodat_fdcwd);
+ ATF_TP_ADD_TC(tp, fchmodat_fdcwderr);
+ ATF_TP_ADD_TC(tp, fchmodat_fderr1);
+ ATF_TP_ADD_TC(tp, fchmodat_fderr2);
+ ATF_TP_ADD_TC(tp, fchmodat_fderr3);
+ ATF_TP_ADD_TC(tp, fchmodat_fdlink);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_fchownat.c b/contrib/netbsd-tests/lib/libc/c063/t_fchownat.c
new file mode 100644
index 000000000000..631d55ac521c
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/c063/t_fchownat.c
@@ -0,0 +1,248 @@
+/* $NetBSD: t_fchownat.c,v 1.4 2017/01/10 15:13:56 christos Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_fchownat.c,v 1.4 2017/01/10 15:13:56 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <pwd.h>
+
+#define DIR "dir"
+#define FILE "dir/fchownat"
+#define BASEFILE "fchownat"
+#define LINK "dir/symlink"
+#define BASELINK "symlink"
+#define FILEERR "dir/fchownaterr"
+#define USER "nobody"
+
+static int getuser(uid_t *, gid_t *);
+
+static int getuser(uid_t *uid, gid_t *gid)
+{
+ struct passwd *pw;
+
+ if ((pw = getpwnam(USER)) == NULL)
+ return -1;
+
+ *uid = pw->pw_uid;
+ *gid = pw->pw_gid;
+
+ return 0;
+}
+
+ATF_TC(fchownat_fd);
+ATF_TC_HEAD(fchownat_fd, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that fchownat works with fd");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(fchownat_fd, tc)
+{
+ int dfd;
+ int fd;
+ uid_t uid;
+ gid_t gid;
+ struct stat st;
+
+ ATF_REQUIRE(getuser(&uid, &gid) == 0);
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(fchownat(dfd, BASEFILE, uid, gid, 0) == 0);
+ ATF_REQUIRE(close(dfd) == 0);
+
+ ATF_REQUIRE(stat(FILE, &st) == 0);
+ ATF_REQUIRE(st.st_uid == uid);
+ ATF_REQUIRE(st.st_gid == gid);
+}
+
+ATF_TC(fchownat_fdcwd);
+ATF_TC_HEAD(fchownat_fdcwd, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that fchownat works with fd as AT_FDCWD");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(fchownat_fdcwd, tc)
+{
+ int fd;
+ uid_t uid;
+ gid_t gid;
+ struct stat st;
+
+ ATF_REQUIRE(getuser(&uid, &gid) == 0);
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(chdir(DIR) == 0);
+ ATF_REQUIRE(fchownat(AT_FDCWD, BASEFILE, uid, gid, 0) == 0);
+
+ ATF_REQUIRE(stat(BASEFILE, &st) == 0);
+ ATF_REQUIRE(st.st_uid == uid);
+ ATF_REQUIRE(st.st_gid == gid);
+}
+
+ATF_TC(fchownat_fdcwderr);
+ATF_TC_HEAD(fchownat_fdcwderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that fchownat fails with fd as AT_FDCWD and bad path");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(fchownat_fdcwderr, tc)
+{
+ uid_t uid;
+ gid_t gid;
+
+ ATF_REQUIRE(getuser(&uid, &gid) == 0);
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE(fchownat(AT_FDCWD, FILEERR, uid, gid, 0) == -1);
+}
+
+ATF_TC(fchownat_fderr1);
+ATF_TC_HEAD(fchownat_fderr1, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that fchownat fail with bad path");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(fchownat_fderr1, tc)
+{
+ int dfd;
+ uid_t uid;
+ gid_t gid;
+
+ ATF_REQUIRE(getuser(&uid, &gid) == 0);
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(fchownat(dfd, FILEERR, uid, gid, 0) == -1);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(fchownat_fderr2);
+ATF_TC_HEAD(fchownat_fderr2, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that fchownat fails with bad fdat");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(fchownat_fderr2, tc)
+{
+ int dfd;
+ int fd;
+ char cwd[MAXPATHLEN];
+ uid_t uid;
+ gid_t gid;
+
+ ATF_REQUIRE(getuser(&uid, &gid) == 0);
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(fchownat(dfd, BASEFILE, uid, gid, 0) == -1);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(fchownat_fderr3);
+ATF_TC_HEAD(fchownat_fderr3, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that fchownat fails with fd as -1");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(fchownat_fderr3, tc)
+{
+ int fd;
+ uid_t uid;
+ gid_t gid;
+
+ ATF_REQUIRE(getuser(&uid, &gid) == 0);
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(fchownat(-1, FILE, uid, gid, 0) == -1);
+}
+
+ATF_TC(fchownat_fdlink);
+ATF_TC_HEAD(fchownat_fdlink, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that fchownat works on symlink");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(fchownat_fdlink, tc)
+{
+ int dfd;
+ uid_t uid;
+ gid_t gid;
+ struct stat st;
+
+ ATF_REQUIRE(getuser(&uid, &gid) == 0);
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE(symlink(FILE, LINK) == 0); /* Target does not exists */
+
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+
+ ATF_REQUIRE(fchownat(dfd, BASELINK, uid, gid, 0) == -1);
+ ATF_REQUIRE(errno == ENOENT);
+
+ ATF_REQUIRE(fchownat(dfd, BASELINK, uid, gid,
+ AT_SYMLINK_NOFOLLOW) == 0);
+
+ ATF_REQUIRE(close(dfd) == 0);
+
+ ATF_REQUIRE(lstat(LINK, &st) == 0);
+ ATF_REQUIRE(st.st_uid == uid);
+ ATF_REQUIRE(st.st_gid == gid);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, fchownat_fd);
+ ATF_TP_ADD_TC(tp, fchownat_fdcwd);
+ ATF_TP_ADD_TC(tp, fchownat_fdcwderr);
+ ATF_TP_ADD_TC(tp, fchownat_fderr1);
+ ATF_TP_ADD_TC(tp, fchownat_fderr2);
+ ATF_TP_ADD_TC(tp, fchownat_fderr3);
+ ATF_TP_ADD_TC(tp, fchownat_fdlink);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_fexecve.c b/contrib/netbsd-tests/lib/libc/c063/t_fexecve.c
new file mode 100644
index 000000000000..b9aa0170f885
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/c063/t_fexecve.c
@@ -0,0 +1,95 @@
+/* $NetBSD: t_fexecve.c,v 1.3 2017/01/10 15:15:09 christos Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_fexecve.c,v 1.3 2017/01/10 15:15:09 christos Exp $");
+
+#include <sys/wait.h>
+
+#include <atf-c.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/param.h>
+
+ATF_TC(fexecve);
+ATF_TC_HEAD(fexecve, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that fexecve works");
+}
+ATF_TC_BODY(fexecve, tc)
+{
+ int status;
+ pid_t pid;
+ const char *const argv[] = { "touch", "test", NULL };
+ const char *const envp[] = { NULL };
+
+ ATF_REQUIRE((pid = fork()) != -1);
+ if (pid == 0) {
+ int fd;
+
+ if ((fd = open("/usr/bin/touch", O_RDONLY, 0)) == -1)
+ err(EXIT_FAILURE, "open /usr/bin/touch");
+
+ if (fexecve(fd, __UNCONST(argv), __UNCONST(envp)) == -1) {
+ int error;
+ if (errno == ENOSYS)
+ error = 76;
+ else
+ error = EXIT_FAILURE;
+ (void)close(fd);
+ err(error, "fexecve");
+ }
+ }
+
+ ATF_REQUIRE(waitpid(pid, &status, 0) != -1);
+ if (!WIFEXITED(status))
+ atf_tc_fail("child process did not exit cleanly");
+ if (WEXITSTATUS(status) == 76)
+ atf_tc_expect_fail("fexecve not implemented");
+ else
+ ATF_REQUIRE(WEXITSTATUS(status) == EXIT_SUCCESS);
+
+ ATF_REQUIRE(access("test", F_OK) == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, fexecve);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_fstatat.c b/contrib/netbsd-tests/lib/libc/c063/t_fstatat.c
new file mode 100644
index 000000000000..c17961f26494
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/c063/t_fstatat.c
@@ -0,0 +1,197 @@
+/* $NetBSD: t_fstatat.c,v 1.3 2017/01/10 15:13:56 christos Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_fstatat.c,v 1.3 2017/01/10 15:13:56 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#define DIR "dir"
+#define FILE "dir/fstatat"
+#define BASEFILE "fstatat"
+#define LINK "dir/symlink"
+#define BASELINK "symlink"
+#define FILEERR "dir/symlink"
+
+ATF_TC(fstatat_fd);
+ATF_TC_HEAD(fstatat_fd, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that fstatat works with fd");
+}
+ATF_TC_BODY(fstatat_fd, tc)
+{
+ int dfd;
+ int fd;
+ struct stat st1, st2;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(fstatat(dfd, BASEFILE, &st1, 0) == 0);
+ ATF_REQUIRE(close(dfd) == 0);
+
+ ATF_REQUIRE(stat(FILE, &st2) == 0);
+ ATF_REQUIRE(memcmp(&st1, &st2, sizeof(st1)) == 0);
+}
+
+ATF_TC(fstatat_fdcwd);
+ATF_TC_HEAD(fstatat_fdcwd, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that fstatat works with fd as AT_FDCWD");
+}
+ATF_TC_BODY(fstatat_fdcwd, tc)
+{
+ int fd;
+ struct stat st;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(chdir(DIR) == 0);
+ ATF_REQUIRE(fstatat(AT_FDCWD, BASEFILE, &st, 0) == 0);
+}
+
+ATF_TC(fstatat_fdcwderr);
+ATF_TC_HEAD(fstatat_fdcwderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that fstatat fails with fd as AT_FDCWD and bad path");
+}
+ATF_TC_BODY(fstatat_fdcwderr, tc)
+{
+ struct stat st;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE(fstatat(AT_FDCWD, FILEERR, &st, 0) == -1);
+}
+
+ATF_TC(fstatat_fderr1);
+ATF_TC_HEAD(fstatat_fderr1, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that fstatat fail with bad path");
+}
+ATF_TC_BODY(fstatat_fderr1, tc)
+{
+ int dfd;
+ struct stat st;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(fstatat(dfd, FILEERR, &st, 0) == -1);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(fstatat_fderr2);
+ATF_TC_HEAD(fstatat_fderr2, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that fstatat fails with bad fdat");
+}
+ATF_TC_BODY(fstatat_fderr2, tc)
+{
+ int dfd;
+ int fd;
+ char cwd[MAXPATHLEN];
+ struct stat st;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(fstatat(dfd, BASEFILE, &st, 0) == -1);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(fstatat_fderr3);
+ATF_TC_HEAD(fstatat_fderr3, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that fstatat fails with fd as -1");
+}
+ATF_TC_BODY(fstatat_fderr3, tc)
+{
+ int fd;
+ struct stat st;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(fstatat(-1, FILE, &st, 0) == -1);
+}
+
+ATF_TC(fstatat_fdlink);
+ATF_TC_HEAD(fstatat_fdlink, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that fstatat works on symlink");
+}
+ATF_TC_BODY(fstatat_fdlink, tc)
+{
+ int dfd;
+ struct stat st;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE(symlink(FILE, LINK) == 0); /* target does not exists */
+
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+
+ ATF_REQUIRE(fstatat(dfd, BASELINK, &st, 0) == -1);
+ ATF_REQUIRE(errno == ENOENT);
+
+ ATF_REQUIRE(fstatat(dfd, BASELINK, &st, AT_SYMLINK_NOFOLLOW) == 0);
+
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, fstatat_fd);
+ ATF_TP_ADD_TC(tp, fstatat_fdcwd);
+ ATF_TP_ADD_TC(tp, fstatat_fdcwderr);
+ ATF_TP_ADD_TC(tp, fstatat_fderr1);
+ ATF_TP_ADD_TC(tp, fstatat_fderr2);
+ ATF_TP_ADD_TC(tp, fstatat_fderr3);
+ ATF_TP_ADD_TC(tp, fstatat_fdlink);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_linkat.c b/contrib/netbsd-tests/lib/libc/c063/t_linkat.c
new file mode 100644
index 000000000000..b49a3f0175a1
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/c063/t_linkat.c
@@ -0,0 +1,217 @@
+/* $NetBSD: t_linkat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_linkat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $");
+
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#define ODIR "olddir"
+#define NDIR "newdir"
+#define FILE "olddir/old"
+#define BASEFILE "old"
+#define RELFILE "../olddir/old"
+#define TARGET "newdir/new"
+#define BASETARGET "new"
+#define LINK "olddir/symlink"
+#define BASELINK "symlink"
+#define FILEERR "olddir/olderr"
+
+ATF_TC(linkat_fd);
+ATF_TC_HEAD(linkat_fd, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that linkat works with fd");
+}
+ATF_TC_BODY(linkat_fd, tc)
+{
+ int ofd, nfd, fd;
+ struct stat ost, nst;
+
+ ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
+ ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) != -1);
+
+ ATF_REQUIRE((ofd = open(ODIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE((nfd = open(NDIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(linkat(ofd, BASEFILE, nfd, BASETARGET, 0) == 0);
+ ATF_REQUIRE(close(ofd) == 0);
+ ATF_REQUIRE(close(nfd) == 0);
+
+ ATF_REQUIRE(stat(FILE, &ost) == 0);
+ ATF_REQUIRE(stat(TARGET, &nst) == 0);
+ ATF_REQUIRE(ost.st_ino == nst.st_ino);
+}
+
+ATF_TC(linkat_fdcwd);
+ATF_TC_HEAD(linkat_fdcwd, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that linkat works with fd as AT_FDCWD");
+}
+ATF_TC_BODY(linkat_fdcwd, tc)
+{
+ int fd;
+ struct stat ost, nst;
+
+ ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
+ ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) != -1);
+
+ ATF_REQUIRE(linkat(AT_FDCWD, FILE, AT_FDCWD, TARGET, 0) == 0);
+
+ ATF_REQUIRE(stat(FILE, &ost) == 0);
+ ATF_REQUIRE(stat(TARGET, &nst) == 0);
+ ATF_REQUIRE(ost.st_ino == nst.st_ino);
+}
+
+ATF_TC(linkat_fdcwderr);
+ATF_TC_HEAD(linkat_fdcwderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that linkat fails with fd as AT_FDCWD and bad path");
+}
+ATF_TC_BODY(linkat_fdcwderr, tc)
+{
+ int fd;
+
+ ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
+ ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) != -1);
+
+ ATF_REQUIRE(linkat(AT_FDCWD, FILEERR, AT_FDCWD, TARGET, 0) == -1);
+}
+
+ATF_TC(linkat_fderr);
+ATF_TC_HEAD(linkat_fderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that linkat fails with fd as -1");
+}
+ATF_TC_BODY(linkat_fderr, tc)
+{
+ int fd;
+
+ ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
+ ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) != -1);
+
+ ATF_REQUIRE(linkat(-1, FILE, AT_FDCWD, TARGET, 0) == -1);
+ ATF_REQUIRE(linkat(AT_FDCWD, FILE, -1, TARGET, 0) == -1);
+ ATF_REQUIRE(linkat(-1, FILE, -1, TARGET, 0) == -1);
+}
+
+ATF_TC(linkat_fdlink1);
+ATF_TC_HEAD(linkat_fdlink1, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that linkat works on symlink target");
+}
+ATF_TC_BODY(linkat_fdlink1, tc)
+{
+ int ofd, nfd, fd;
+ struct stat ost, nst;
+
+ ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
+ ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) != -1);
+ ATF_REQUIRE(symlink(RELFILE, LINK) == 0);
+
+ ATF_REQUIRE((ofd = open(ODIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE((nfd = open(NDIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(linkat(ofd, BASELINK, nfd, BASETARGET,
+ AT_SYMLINK_FOLLOW) == 0);
+ ATF_REQUIRE(close(ofd) == 0);
+ ATF_REQUIRE(close(nfd) == 0);
+
+ ATF_REQUIRE(lstat(LINK, &ost) == 0);
+ ATF_REQUIRE(lstat(TARGET, &nst) == 0);
+ ATF_REQUIRE(ost.st_ino != nst.st_ino);
+
+ ATF_REQUIRE(lstat(FILE, &ost) == 0);
+ ATF_REQUIRE(lstat(TARGET, &nst) == 0);
+ ATF_REQUIRE(ost.st_ino == nst.st_ino);
+}
+
+
+ATF_TC(linkat_fdlink2);
+ATF_TC_HEAD(linkat_fdlink2, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that linkat works on symlink source");
+}
+ATF_TC_BODY(linkat_fdlink2, tc)
+{
+ int ofd, nfd, fd;
+ struct stat ost, nst;
+
+ ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
+ ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) != -1);
+ ATF_REQUIRE(symlink(RELFILE, LINK) == 0);
+
+ ATF_REQUIRE((ofd = open(ODIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE((nfd = open(NDIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(linkat(ofd, BASELINK, nfd, BASETARGET, 0) == 0);
+ ATF_REQUIRE(close(ofd) == 0);
+ ATF_REQUIRE(close(nfd) == 0);
+
+ ATF_REQUIRE(lstat(LINK, &ost) == 0);
+ ATF_REQUIRE(lstat(TARGET, &nst) == 0);
+ ATF_REQUIRE(ost.st_ino == nst.st_ino);
+
+ ATF_REQUIRE(lstat(FILE, &ost) == 0);
+ ATF_REQUIRE(lstat(TARGET, &nst) == 0);
+ ATF_REQUIRE(ost.st_ino != nst.st_ino);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, linkat_fd);
+ ATF_TP_ADD_TC(tp, linkat_fdcwd);
+ ATF_TP_ADD_TC(tp, linkat_fdcwderr);
+ ATF_TP_ADD_TC(tp, linkat_fderr);
+ ATF_TP_ADD_TC(tp, linkat_fdlink1);
+ ATF_TP_ADD_TC(tp, linkat_fdlink2);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_mkdirat.c b/contrib/netbsd-tests/lib/libc/c063/t_mkdirat.c
new file mode 100644
index 000000000000..23c53d79a46f
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/c063/t_mkdirat.c
@@ -0,0 +1,120 @@
+/* $NetBSD: t_mkdirat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_mkdirat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $");
+
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#define DIR "dir"
+#define SDIR "dir/openat"
+#define BASESDIR "openat"
+#define SDIRERR "dir/openaterr"
+
+ATF_TC(mkdirat_fd);
+ATF_TC_HEAD(mkdirat_fd, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that mkdirat works with fd");
+}
+ATF_TC_BODY(mkdirat_fd, tc)
+{
+ int dfd;
+ mode_t mode = 0755;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(mkdirat(dfd, BASESDIR, mode) != -1);
+ ATF_REQUIRE(close(dfd) == 0);
+ ATF_REQUIRE(access(SDIR, F_OK) == 0);
+}
+
+ATF_TC(mkdirat_fdcwd);
+ATF_TC_HEAD(mkdirat_fdcwd, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that mkdirat works with fd as AT_FDCWD");
+}
+ATF_TC_BODY(mkdirat_fdcwd, tc)
+{
+ mode_t mode = 0755;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE(mkdirat(AT_FDCWD, SDIR, mode) != -1);
+ ATF_REQUIRE(access(SDIR, F_OK) == 0);
+}
+
+ATF_TC(mkdirat_fdcwderr);
+ATF_TC_HEAD(mkdirat_fdcwderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that mkdirat fails with fd as AT_FDCWD and bad path");
+}
+ATF_TC_BODY(mkdirat_fdcwderr, tc)
+{
+ mode_t mode = 0755;
+
+ ATF_REQUIRE(mkdirat(AT_FDCWD, SDIRERR, mode) == -1);
+}
+
+ATF_TC(mkdirat_fderr);
+ATF_TC_HEAD(mkdirat_fderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that mkdirat fails with fd as -1");
+}
+ATF_TC_BODY(mkdirat_fderr, tc)
+{
+ int fd;
+ mode_t mode = 0755;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(SDIR, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+ ATF_REQUIRE(mkdirat(-1, SDIR, mode) == -1);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, mkdirat_fd);
+ ATF_TP_ADD_TC(tp, mkdirat_fdcwd);
+ ATF_TP_ADD_TC(tp, mkdirat_fdcwderr);
+ ATF_TP_ADD_TC(tp, mkdirat_fderr);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_mkfifoat.c b/contrib/netbsd-tests/lib/libc/c063/t_mkfifoat.c
new file mode 100644
index 000000000000..4f91afd979a7
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/c063/t_mkfifoat.c
@@ -0,0 +1,120 @@
+/* $NetBSD: t_mkfifoat.c,v 1.4 2017/01/14 20:55:26 christos Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_mkfifoat.c,v 1.4 2017/01/14 20:55:26 christos Exp $");
+
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#define DIR "dir"
+#define FIFO "dir/openat"
+#define BASEFIFO "openat"
+#define FIFOERR "dir/openaterr"
+
+ATF_TC(mkfifoat_fd);
+ATF_TC_HEAD(mkfifoat_fd, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that mkfifoat works with fd");
+}
+ATF_TC_BODY(mkfifoat_fd, tc)
+{
+ int dfd;
+ mode_t mode = 0600;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(mkfifoat(dfd, BASEFIFO, mode) != -1);
+ ATF_REQUIRE(access(FIFO, F_OK) == 0);
+ (void)close(dfd);
+}
+
+ATF_TC(mkfifoat_fdcwd);
+ATF_TC_HEAD(mkfifoat_fdcwd, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that mkfifoat works with fd as AT_FDCWD");
+}
+ATF_TC_BODY(mkfifoat_fdcwd, tc)
+{
+ mode_t mode = 0600;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE(mkfifoat(AT_FDCWD, FIFO, mode) != -1);
+ ATF_REQUIRE(access(FIFO, F_OK) == 0);
+}
+
+ATF_TC(mkfifoat_fdcwderr);
+ATF_TC_HEAD(mkfifoat_fdcwderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that mkfifoat fails with fd as AT_FDCWD and bad path");
+}
+ATF_TC_BODY(mkfifoat_fdcwderr, tc)
+{
+ mode_t mode = 0600;
+
+ ATF_REQUIRE(mkfifoat(AT_FDCWD, FIFOERR, mode) == -1);
+}
+
+ATF_TC(mkfifoat_fderr);
+ATF_TC_HEAD(mkfifoat_fderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that mkfifoat fails with fd as -1");
+}
+ATF_TC_BODY(mkfifoat_fderr, tc)
+{
+ int fd;
+ mode_t mode = 0600;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FIFO, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+ ATF_REQUIRE(mkfifoat(-1, FIFO, mode) == -1);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, mkfifoat_fd);
+ ATF_TP_ADD_TC(tp, mkfifoat_fdcwd);
+ ATF_TP_ADD_TC(tp, mkfifoat_fdcwderr);
+ ATF_TP_ADD_TC(tp, mkfifoat_fderr);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_mknodat.c b/contrib/netbsd-tests/lib/libc/c063/t_mknodat.c
new file mode 100644
index 000000000000..7c3ab9b2edbe
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/c063/t_mknodat.c
@@ -0,0 +1,151 @@
+/* $NetBSD: t_mknodat.c,v 1.4 2017/01/10 15:15:09 christos Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_mknodat.c,v 1.4 2017/01/10 15:15:09 christos Exp $");
+
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#define DIR "dir"
+#define FILE "dir/openat"
+#define BASEFILE "openat"
+#define FILEERR "dir/openaterr"
+
+static dev_t get_devnull(void);
+
+static dev_t
+get_devnull(void)
+{
+ struct stat st;
+
+ if (stat(_PATH_DEVNULL, &st) != 0)
+ return NODEV;
+
+ return st.st_rdev;
+}
+
+
+ATF_TC(mknodat_fd);
+ATF_TC_HEAD(mknodat_fd, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that mknodat works with fd");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(mknodat_fd, tc)
+{
+ int dfd;
+ int fd;
+ dev_t dev;
+ mode_t mode = S_IFCHR|0600;
+
+ ATF_REQUIRE((dev = get_devnull()) != NODEV);
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE((fd = mknodat(dfd, BASEFILE, mode, dev)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+ ATF_REQUIRE(access(FILE, F_OK) == 0);
+ (void)close(dfd);
+}
+
+ATF_TC(mknodat_fdcwd);
+ATF_TC_HEAD(mknodat_fdcwd, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that mknodat works with fd as AT_FDCWD");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(mknodat_fdcwd, tc)
+{
+ int fd;
+ dev_t dev;
+ mode_t mode = S_IFCHR|0600;
+
+ ATF_REQUIRE((dev = get_devnull()) != NODEV);
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = mknodat(AT_FDCWD, FILE, mode, dev)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+ ATF_REQUIRE(access(FILE, F_OK) == 0);
+}
+
+ATF_TC(mknodat_fdcwderr);
+ATF_TC_HEAD(mknodat_fdcwderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that mknodat fails with fd as AT_FDCWD and bad path");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(mknodat_fdcwderr, tc)
+{
+ int fd;
+ dev_t dev;
+ mode_t mode = S_IFCHR|0600;
+
+ ATF_REQUIRE((dev = get_devnull()) != NODEV);
+ ATF_REQUIRE((fd = mknodat(AT_FDCWD, FILEERR, mode, dev)) == -1);
+}
+
+ATF_TC(mknodat_fderr);
+ATF_TC_HEAD(mknodat_fderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that mknodat fails with fd as -1");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(mknodat_fderr, tc)
+{
+ int fd;
+ dev_t dev;
+ mode_t mode = S_IFCHR|0600;
+
+ ATF_REQUIRE((dev = get_devnull()) != NODEV);
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+ ATF_REQUIRE((fd = mknodat(-1, FILE, mode, dev)) == -1);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, mknodat_fd);
+ ATF_TP_ADD_TC(tp, mknodat_fdcwd);
+ ATF_TP_ADD_TC(tp, mknodat_fdcwderr);
+ ATF_TP_ADD_TC(tp, mknodat_fderr);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_o_search.c b/contrib/netbsd-tests/lib/libc/c063/t_o_search.c
new file mode 100644
index 000000000000..dd4fbff97b82
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/c063/t_o_search.c
@@ -0,0 +1,365 @@
+/* $NetBSD: t_o_search.c,v 1.10 2020/02/08 19:58:36 kamil Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_o_search.c,v 1.10 2020/02/08 19:58:36 kamil Exp $");
+
+#include <atf-c.h>
+
+#include <sys/types.h>
+#include <sys/mount.h>
+#include <sys/statvfs.h>
+#include <sys/stat.h>
+
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <pwd.h>
+
+/*
+ * dholland 20130112: disable tests that require O_SEARCH semantics
+ * until a decision is reached about the semantics of O_SEARCH and a
+ * non-broken implementation is available.
+ */
+#if defined(__FreeBSD__) || (O_MASK & O_SEARCH) != 0
+#define USE_O_SEARCH
+#endif
+
+#ifdef __FreeBSD__
+#define statvfs statfs
+#define fstatvfs fstatfs
+#endif
+
+#define DIR "dir"
+#define FILE "dir/o_search"
+#define BASEFILE "o_search"
+
+
+ATF_TC(o_search_perm1);
+ATF_TC_HEAD(o_search_perm1, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that openat enforces search permission");
+ atf_tc_set_md_var(tc, "require.user", "unprivileged");
+}
+ATF_TC_BODY(o_search_perm1, tc)
+{
+ int dfd;
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+
+ ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(fchmod(dfd, 0644) == 0);
+
+ ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) == -1);
+ ATF_REQUIRE(errno == EACCES);
+
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+#ifdef USE_O_SEARCH
+
+ATF_TC(o_search_root_flag1);
+ATF_TC_HEAD(o_search_root_flag1, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that root openat honours O_SEARCH");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(o_search_root_flag1, tc)
+{
+ int dfd;
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY|O_SEARCH, 0)) != -1);
+
+ ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(fchmod(dfd, 0644) == 0);
+
+ ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(fchmod(dfd, 0444) == 0);
+
+ ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1);
+
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(o_search_unpriv_flag1);
+ATF_TC_HEAD(o_search_unpriv_flag1, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that openat honours O_SEARCH");
+ atf_tc_set_md_var(tc, "require.user", "unprivileged");
+}
+ATF_TC_BODY(o_search_unpriv_flag1, tc)
+{
+ int dfd;
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY|O_SEARCH, 0)) != -1);
+
+ ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(fchmod(dfd, 0644) == 0);
+
+ ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(fchmod(dfd, 0444) == 0);
+
+ ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1);
+
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+#endif /* USE_O_SEARCH */
+
+ATF_TC(o_search_perm2);
+ATF_TC_HEAD(o_search_perm2, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that faccessat enforces search permission");
+ atf_tc_set_md_var(tc, "require.user", "unprivileged");
+}
+ATF_TC_BODY(o_search_perm2, tc)
+{
+ int dfd;
+ int fd;
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+
+ ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0);
+
+ ATF_REQUIRE(fchmod(dfd, 0644) == 0);
+
+ ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == -1);
+ ATF_REQUIRE(errno == EACCES);
+
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+#ifdef USE_O_SEARCH
+
+ATF_TC(o_search_root_flag2);
+ATF_TC_HEAD(o_search_root_flag2, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that root fstatat honours O_SEARCH");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(o_search_root_flag2, tc)
+{
+ int dfd;
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY|O_SEARCH, 0)) != -1);
+
+ ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0);
+
+ ATF_REQUIRE(fchmod(dfd, 0644) == 0);
+
+ ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0);
+
+ ATF_REQUIRE(fchmod(dfd, 0444) == 0);
+
+ ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0);
+
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(o_search_unpriv_flag2);
+ATF_TC_HEAD(o_search_unpriv_flag2, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that fstatat honours O_SEARCH");
+ atf_tc_set_md_var(tc, "require.user", "unprivileged");
+}
+ATF_TC_BODY(o_search_unpriv_flag2, tc)
+{
+ int dfd;
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY|O_SEARCH, 0)) != -1);
+
+ ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0);
+
+ ATF_REQUIRE(fchmod(dfd, 0644) == 0);
+
+ ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0);
+
+ ATF_REQUIRE(fchmod(dfd, 0444) == 0);
+
+ ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0);
+
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+#endif /* USE_O_SEARCH */
+
+
+ATF_TC(o_search_notdir);
+ATF_TC_HEAD(o_search_notdir, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that openat fails with non dir fd");
+}
+ATF_TC_BODY(o_search_notdir, tc)
+{
+ int dfd;
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((dfd = open(FILE, O_CREAT|O_SEARCH, 0644)) != -1);
+ ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) == -1);
+ ATF_REQUIRE(errno == ENOTDIR);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+#ifdef USE_O_SEARCH
+ATF_TC(o_search_nord);
+ATF_TC_HEAD(o_search_nord, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that openat succeeds with no read permission");
+ atf_tc_set_md_var(tc, "require.user", "unprivileged");
+}
+ATF_TC_BODY(o_search_nord, tc)
+{
+ int dfd, fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(chmod(DIR, 0100) == 0);
+ ATF_REQUIRE((dfd = open(DIR, O_SEARCH, 0)) != -1);
+
+ ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) != -1);
+
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(o_search_getdents);
+ATF_TC_HEAD(o_search_getdents, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that O_SEARCH forbids getdents");
+}
+ATF_TC_BODY(o_search_getdents, tc)
+{
+ char buf[1024];
+ int dfd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((dfd = open(DIR, O_SEARCH, 0)) != -1);
+ ATF_REQUIRE(getdents(dfd, buf, sizeof(buf)) < 0);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(o_search_revokex);
+ATF_TC_HEAD(o_search_revokex, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that *at behaves after chmod -x");
+ atf_tc_set_md_var(tc, "require.user", "unprivileged");
+}
+ATF_TC_BODY(o_search_revokex, tc)
+{
+ struct statvfs vst;
+ struct stat sb;
+ int dfd, fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(DIR, O_SEARCH, 0)) != -1);
+
+ /* Drop permissions. The kernel must still not check the exec bit. */
+ ATF_REQUIRE(chmod(DIR, 0000) == 0);
+
+ fstatvfs(dfd, &vst);
+ if (strcmp(vst.f_fstypename, "nfs") == 0)
+ atf_tc_expect_fail("NFS protocol cannot observe O_SEARCH semantics");
+
+ ATF_REQUIRE(fstatat(dfd, BASEFILE, &sb, 0) == 0);
+
+ ATF_REQUIRE(close(dfd) == 0);
+}
+#endif /* USE_O_SEARCH */
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, o_search_perm1);
+#ifdef USE_O_SEARCH
+ ATF_TP_ADD_TC(tp, o_search_root_flag1);
+ ATF_TP_ADD_TC(tp, o_search_unpriv_flag1);
+#endif
+ ATF_TP_ADD_TC(tp, o_search_perm2);
+#ifdef USE_O_SEARCH
+ ATF_TP_ADD_TC(tp, o_search_root_flag2);
+ ATF_TP_ADD_TC(tp, o_search_unpriv_flag2);
+#endif
+ ATF_TP_ADD_TC(tp, o_search_notdir);
+#ifdef USE_O_SEARCH
+ ATF_TP_ADD_TC(tp, o_search_nord);
+ ATF_TP_ADD_TC(tp, o_search_getdents);
+ ATF_TP_ADD_TC(tp, o_search_revokex);
+#endif
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_openat.c b/contrib/netbsd-tests/lib/libc/c063/t_openat.c
new file mode 100644
index 000000000000..f7c8c74b5b15
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/c063/t_openat.c
@@ -0,0 +1,166 @@
+/* $NetBSD: t_openat.c,v 1.3 2017/01/10 15:13:56 christos Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_openat.c,v 1.3 2017/01/10 15:13:56 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#define DIR "dir"
+#define FILE "dir/openat"
+#define BASEFILE "openat"
+#define FILEERR "dir/openaterr"
+
+ATF_TC(openat_fd);
+ATF_TC_HEAD(openat_fd, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that openat works with fd");
+}
+ATF_TC_BODY(openat_fd, tc)
+{
+ int dfd;
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(close(dfd) == 0);
+ ATF_REQUIRE(close(fd) == 0);
+}
+
+ATF_TC(openat_fdcwd);
+ATF_TC_HEAD(openat_fdcwd, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that openat works with fd as AT_FDCWD");
+}
+ATF_TC_BODY(openat_fdcwd, tc)
+{
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(chdir(DIR) == 0);
+ ATF_REQUIRE((fd = openat(AT_FDCWD, BASEFILE, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+}
+
+ATF_TC(openat_fdcwderr);
+ATF_TC_HEAD(openat_fdcwderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that openat fails with fd as AT_FDCWD and bad path");
+}
+ATF_TC_BODY(openat_fdcwderr, tc)
+{
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = openat(AT_FDCWD, FILEERR, O_RDONLY, 0)) == -1);
+}
+
+ATF_TC(openat_fderr1);
+ATF_TC_HEAD(openat_fderr1, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that openat fail with bad path");
+}
+ATF_TC_BODY(openat_fderr1, tc)
+{
+ int dfd;
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE((fd = openat(dfd, FILEERR, O_RDONLY, 0)) == -1);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(openat_fderr2);
+ATF_TC_HEAD(openat_fderr2, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that openat fails with bad fdat");
+}
+ATF_TC_BODY(openat_fderr2, tc)
+{
+ int dfd;
+ int fd;
+ char cwd[MAXPATHLEN];
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1);
+ ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDONLY, 0)) == -1);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(openat_fderr3);
+ATF_TC_HEAD(openat_fderr3, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that openat fails with fd as -1");
+}
+ATF_TC_BODY(openat_fderr3, tc)
+{
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((fd = openat(-1, FILE, O_RDONLY, 0)) == -1);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, openat_fd);
+ ATF_TP_ADD_TC(tp, openat_fdcwd);
+ ATF_TP_ADD_TC(tp, openat_fdcwderr);
+ ATF_TP_ADD_TC(tp, openat_fderr1);
+ ATF_TP_ADD_TC(tp, openat_fderr2);
+ ATF_TP_ADD_TC(tp, openat_fderr3);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_readlinkat.c b/contrib/netbsd-tests/lib/libc/c063/t_readlinkat.c
new file mode 100644
index 000000000000..cf14652a9efe
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/c063/t_readlinkat.c
@@ -0,0 +1,158 @@
+/* $NetBSD: t_readlinkat.c,v 1.4 2017/01/10 15:13:56 christos Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_readlinkat.c,v 1.4 2017/01/10 15:13:56 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#define DIR "dir"
+#define FILE "dir/readlinkat"
+#define BASEFILE "readlinkat"
+#define LINK "dir/symlink"
+#define BASELINK "symlink"
+#define FILEERR "dir/readlinkaterr"
+
+ATF_TC(readlinkat_fd);
+ATF_TC_HEAD(readlinkat_fd, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that readlinkat works with fd");
+}
+ATF_TC_BODY(readlinkat_fd, tc)
+{
+ int dfd;
+ int fd;
+ ssize_t len;
+ char buf[MAXPATHLEN];
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+ ATF_REQUIRE(symlink(FILE, LINK) == 0);
+
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ len = readlinkat(dfd, BASELINK, buf, sizeof(buf)-1);
+ ATF_REQUIRE(len != -1);
+ buf[len] = 0;
+ ATF_REQUIRE(close(dfd) == 0);
+
+ ATF_REQUIRE(strcmp(buf, FILE) == 0);
+}
+
+ATF_TC(readlinkat_fdcwd);
+ATF_TC_HEAD(readlinkat_fdcwd, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that readlinkat works with fd as AT_FDCWD");
+}
+ATF_TC_BODY(readlinkat_fdcwd, tc)
+{
+ int fd;
+ ssize_t len;
+ char buf[MAXPATHLEN];
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+ ATF_REQUIRE(symlink(FILE, LINK) == 0);
+
+ len = readlinkat(AT_FDCWD, LINK, buf, sizeof(buf)-1);
+ ATF_REQUIRE(len != -1);
+ buf[len] = 0;
+
+ ATF_REQUIRE(strcmp(buf, FILE) == 0);
+}
+
+ATF_TC(readlinkat_fdcwderr);
+ATF_TC_HEAD(readlinkat_fdcwderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that readlinkat fails with fd as AT_FDCWD and bad path");
+}
+ATF_TC_BODY(readlinkat_fdcwderr, tc)
+{
+ char buf[MAXPATHLEN];
+
+ ATF_REQUIRE(readlinkat(AT_FDCWD, LINK, buf, sizeof(buf)) == -1);
+}
+
+ATF_TC(readlinkat_fderr1);
+ATF_TC_HEAD(readlinkat_fderr1, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that readlinkat fail with bad path");
+}
+ATF_TC_BODY(readlinkat_fderr1, tc)
+{
+ int dfd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(readlinkat(dfd, FILEERR, F_OK, 0) == -1);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(readlinkat_fderr2);
+ATF_TC_HEAD(readlinkat_fderr2, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that readlinkat fails with fd as -1");
+}
+ATF_TC_BODY(readlinkat_fderr2, tc)
+{
+ int fd;
+ char buf[MAXPATHLEN];
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+ ATF_REQUIRE(symlink(FILE, LINK) == 0);
+
+ ATF_REQUIRE(readlinkat(-1, LINK, buf, sizeof(buf)) == -1);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, readlinkat_fd);
+ ATF_TP_ADD_TC(tp, readlinkat_fdcwd);
+ ATF_TP_ADD_TC(tp, readlinkat_fdcwderr);
+ ATF_TP_ADD_TC(tp, readlinkat_fderr1);
+ ATF_TP_ADD_TC(tp, readlinkat_fderr2);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_renameat.c b/contrib/netbsd-tests/lib/libc/c063/t_renameat.c
new file mode 100644
index 000000000000..e297f2a629af
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/c063/t_renameat.c
@@ -0,0 +1,152 @@
+/* $NetBSD: t_renameat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_renameat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $");
+
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#define ODIR "olddir"
+#define NDIR "newdir"
+#define FILE "olddir/old"
+#define BASEFILE "old"
+#define RELFILE "../olddir/old"
+#define TARGET "newdir/new"
+#define BASETARGET "new"
+#define FILEERR "olddir/olderr"
+
+ATF_TC(renameat_fd);
+ATF_TC_HEAD(renameat_fd, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that renameat works with fd");
+}
+ATF_TC_BODY(renameat_fd, tc)
+{
+ int ofd, nfd, fd;
+ struct stat ost, nst;
+
+ ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
+ ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) != -1);
+
+ ATF_REQUIRE(stat(FILE, &ost) == 0);
+
+ ATF_REQUIRE((ofd = open(ODIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE((nfd = open(NDIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(renameat(ofd, BASEFILE, nfd, BASETARGET) == 0);
+ ATF_REQUIRE(close(ofd) == 0);
+ ATF_REQUIRE(close(nfd) == 0);
+
+ ATF_REQUIRE(stat(TARGET, &nst) == 0);
+ ATF_REQUIRE(ost.st_ino == nst.st_ino);
+}
+
+ATF_TC(renameat_fdcwd);
+ATF_TC_HEAD(renameat_fdcwd, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that renameat works with fd as AT_FDCWD");
+}
+
+ATF_TC_BODY(renameat_fdcwd, tc)
+{
+ int fd;
+ struct stat ost, nst;
+
+ ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
+ ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) != -1);
+
+ ATF_REQUIRE(stat(FILE, &ost) == 0);
+
+ ATF_REQUIRE(renameat(AT_FDCWD, FILE, AT_FDCWD, TARGET) == 0);
+
+ ATF_REQUIRE(stat(TARGET, &nst) == 0);
+ ATF_REQUIRE(ost.st_ino == nst.st_ino);
+}
+
+ATF_TC(renameat_fdcwderr);
+ATF_TC_HEAD(renameat_fdcwderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that renameat fails with fd as AT_FDCWD and bad path");
+}
+ATF_TC_BODY(renameat_fdcwderr, tc)
+{
+ int fd;
+
+ ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
+ ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) != -1);
+
+ ATF_REQUIRE(renameat(AT_FDCWD, FILEERR, AT_FDCWD, TARGET) == -1);
+}
+
+ATF_TC(renameat_fderr);
+ATF_TC_HEAD(renameat_fderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that renameat fails with fd as -1");
+}
+ATF_TC_BODY(renameat_fderr, tc)
+{
+ int fd;
+
+ ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
+ ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) != -1);
+
+ ATF_REQUIRE(renameat(-1, FILE, AT_FDCWD, TARGET) == -1);
+ ATF_REQUIRE(renameat(AT_FDCWD, FILE, -1, TARGET) == -1);
+ ATF_REQUIRE(renameat(-1, FILE, -1, TARGET) == -1);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, renameat_fd);
+ ATF_TP_ADD_TC(tp, renameat_fdcwd);
+ ATF_TP_ADD_TC(tp, renameat_fdcwderr);
+ ATF_TP_ADD_TC(tp, renameat_fderr);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_symlinkat.c b/contrib/netbsd-tests/lib/libc/c063/t_symlinkat.c
new file mode 100644
index 000000000000..d62f28912d5a
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/c063/t_symlinkat.c
@@ -0,0 +1,150 @@
+/* $NetBSD: t_symlinkat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_symlinkat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $");
+
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#define ODIR "olddir"
+#define NDIR "newdir"
+#define FILE "olddir/old"
+#define BASEFILE "old"
+#define RELFILE "../olddir/old"
+#define LINK "newdir/symlink"
+#define BASELINK "symlink"
+#define FILEERR "olddir/olderr"
+
+ATF_TC(symlinkat_fd);
+ATF_TC_HEAD(symlinkat_fd, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that symlinkat works with fd");
+}
+ATF_TC_BODY(symlinkat_fd, tc)
+{
+ int dfd, fd;
+ struct stat ost, nst;
+
+ ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
+ ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) != -1);
+
+ ATF_REQUIRE((dfd = open(NDIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(symlinkat(RELFILE, dfd, BASELINK) == 0);
+ ATF_REQUIRE(close(dfd) == 0);
+
+ ATF_REQUIRE(stat(FILE, &ost) == 0);
+ ATF_REQUIRE(stat(LINK, &nst) == 0);
+ ATF_REQUIRE(ost.st_ino == nst.st_ino);
+}
+
+ATF_TC(symlinkat_fdcwd);
+ATF_TC_HEAD(symlinkat_fdcwd, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that symlinkat works with fd as AT_FDCWD");
+}
+ATF_TC_BODY(symlinkat_fdcwd, tc)
+{
+ int fd;
+ struct stat ost, nst;
+
+ ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
+ ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) != -1);
+
+ ATF_REQUIRE(symlinkat(RELFILE, AT_FDCWD, LINK) == 0);
+
+ ATF_REQUIRE(stat(FILE, &ost) == 0);
+ ATF_REQUIRE(stat(LINK, &nst) == 0);
+ ATF_REQUIRE(ost.st_ino == nst.st_ino);
+}
+
+ATF_TC(symlinkat_fdcwderr);
+ATF_TC_HEAD(symlinkat_fdcwderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that symlinkat works with fd as AT_FDCWD and bad path");
+}
+ATF_TC_BODY(symlinkat_fdcwderr, tc)
+{
+ int fd;
+ struct stat st;
+
+ ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
+ ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) != -1);
+
+ ATF_REQUIRE(symlinkat(FILEERR, AT_FDCWD, LINK) == 0);
+ ATF_REQUIRE(lstat(LINK, &st) == 0);
+ ATF_REQUIRE(stat(LINK, &st) == -1);
+ ATF_REQUIRE(errno == ENOENT);
+
+}
+
+ATF_TC(symlinkat_fderr);
+ATF_TC_HEAD(symlinkat_fderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that symlinkat fails with fd as -1");
+}
+ATF_TC_BODY(symlinkat_fderr, tc)
+{
+ int fd;
+
+ ATF_REQUIRE(mkdir(ODIR, 0755) == 0);
+ ATF_REQUIRE(mkdir(NDIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) != -1);
+
+ ATF_REQUIRE(symlinkat(RELFILE, -1, LINK) == -1);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, symlinkat_fd);
+ ATF_TP_ADD_TC(tp, symlinkat_fdcwd);
+ ATF_TP_ADD_TC(tp, symlinkat_fdcwderr);
+ ATF_TP_ADD_TC(tp, symlinkat_fderr);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_unlinkat.c b/contrib/netbsd-tests/lib/libc/c063/t_unlinkat.c
new file mode 100644
index 000000000000..9897b928c516
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/c063/t_unlinkat.c
@@ -0,0 +1,177 @@
+/* $NetBSD: t_unlinkat.c,v 1.3 2017/01/10 15:13:56 christos Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_unlinkat.c,v 1.3 2017/01/10 15:13:56 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#define DIR "dir"
+#define FILE "dir/unlinkat"
+#define BASEFILE "unlinkat"
+#define FILEERR "dir/unlinkaterr"
+
+ATF_TC(unlinkat_fd);
+ATF_TC_HEAD(unlinkat_fd, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that unlinkat works with fd");
+}
+ATF_TC_BODY(unlinkat_fd, tc)
+{
+ int dfd;
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(unlinkat(dfd, BASEFILE, 0) == 0);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(unlinkat_fdcwd);
+ATF_TC_HEAD(unlinkat_fdcwd, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that unlinkat works with fd as AT_FDCWD");
+}
+ATF_TC_BODY(unlinkat_fdcwd, tc)
+{
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(chdir(DIR) == 0);
+ ATF_REQUIRE(unlinkat(AT_FDCWD, BASEFILE, 0) == 0);
+}
+
+ATF_TC(unlinkat_fdcwderr);
+ATF_TC_HEAD(unlinkat_fdcwderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that unlinkat fails with fd as AT_FDCWD and bad path");
+}
+ATF_TC_BODY(unlinkat_fdcwderr, tc)
+{
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE(unlinkat(AT_FDCWD, FILEERR, 0) == -1);
+}
+
+ATF_TC(unlinkat_fderr1);
+ATF_TC_HEAD(unlinkat_fderr1, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that unlinkat fail with bad path");
+}
+ATF_TC_BODY(unlinkat_fderr1, tc)
+{
+ int dfd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(unlinkat(dfd, FILEERR, 0) == -1);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(unlinkat_fderr2);
+ATF_TC_HEAD(unlinkat_fderr2, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that unlinkat fails with bad fdat");
+}
+ATF_TC_BODY(unlinkat_fderr2, tc)
+{
+ int dfd;
+ int fd;
+ char cwd[MAXPATHLEN];
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(unlinkat(dfd, BASEFILE, 0) == -1);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(unlinkat_fderr3);
+ATF_TC_HEAD(unlinkat_fderr3, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that unlinkat fails with fd as -1");
+}
+ATF_TC_BODY(unlinkat_fderr3, tc)
+{
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(unlinkat(-1, FILE, 0) == -1);
+}
+
+ATF_TC(unlinkat_dir);
+ATF_TC_HEAD(unlinkat_dir, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that unlinkat can remove directories");
+}
+ATF_TC_BODY(unlinkat_dir, tc)
+{
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+
+ ATF_REQUIRE(unlinkat(AT_FDCWD, DIR, 0) == -1);
+ ATF_REQUIRE(errno == EPERM);
+ ATF_REQUIRE(unlinkat(AT_FDCWD, DIR, AT_REMOVEDIR) == 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, unlinkat_fd);
+ ATF_TP_ADD_TC(tp, unlinkat_fdcwd);
+ ATF_TP_ADD_TC(tp, unlinkat_fdcwderr);
+ ATF_TP_ADD_TC(tp, unlinkat_fderr1);
+ ATF_TP_ADD_TC(tp, unlinkat_fderr2);
+ ATF_TP_ADD_TC(tp, unlinkat_fderr3);
+ ATF_TP_ADD_TC(tp, unlinkat_dir);
+
+ return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libc/c063/t_utimensat.c b/contrib/netbsd-tests/lib/libc/c063/t_utimensat.c
new file mode 100644
index 000000000000..682c2df06974
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libc/c063/t_utimensat.c
@@ -0,0 +1,213 @@
+/* $NetBSD: t_utimensat.c,v 1.6 2017/01/10 15:13:56 christos Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_utimensat.c,v 1.6 2017/01/10 15:13:56 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#define DIR "dir"
+#define FILE "dir/utimensat"
+#define BASEFILE "utimensat"
+#define LINK "dir/symlink"
+#define BASELINK "symlink"
+#define FILEERR "dir/symlink"
+
+const struct timespec tptr[] = {
+ { 0x12345678, 987654321 },
+ { 0x15263748, 123456789 },
+};
+
+ATF_TC(utimensat_fd);
+ATF_TC_HEAD(utimensat_fd, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that utimensat works with fd");
+}
+ATF_TC_BODY(utimensat_fd, tc)
+{
+ int dfd;
+ int fd;
+ struct stat st;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(utimensat(dfd, BASEFILE, tptr, 0) == 0);
+ ATF_REQUIRE(close(dfd) == 0);
+
+ ATF_REQUIRE(stat(FILE, &st) == 0);
+ ATF_REQUIRE(st.st_atimespec.tv_sec == tptr[0].tv_sec);
+ ATF_REQUIRE(st.st_atimespec.tv_nsec == tptr[0].tv_nsec);
+ ATF_REQUIRE(st.st_mtimespec.tv_sec == tptr[1].tv_sec);
+ ATF_REQUIRE(st.st_mtimespec.tv_nsec == tptr[1].tv_nsec);
+}
+
+ATF_TC(utimensat_fdcwd);
+ATF_TC_HEAD(utimensat_fdcwd, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that utimensat works with fd as AT_FDCWD");
+}
+ATF_TC_BODY(utimensat_fdcwd, tc)
+{
+ int fd;
+ struct stat st;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(chdir(DIR) == 0);
+ ATF_REQUIRE(utimensat(AT_FDCWD, BASEFILE, tptr, 0) == 0);
+
+ ATF_REQUIRE(stat(BASEFILE, &st) == 0);
+ ATF_REQUIRE(st.st_atimespec.tv_sec == tptr[0].tv_sec);
+ ATF_REQUIRE(st.st_atimespec.tv_nsec == tptr[0].tv_nsec);
+ ATF_REQUIRE(st.st_mtimespec.tv_sec == tptr[1].tv_sec);
+ ATF_REQUIRE(st.st_mtimespec.tv_nsec == tptr[1].tv_nsec);
+}
+
+ATF_TC(utimensat_fdcwderr);
+ATF_TC_HEAD(utimensat_fdcwderr, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "See that utimensat fails with fd as AT_FDCWD and bad path");
+}
+ATF_TC_BODY(utimensat_fdcwderr, tc)
+{
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE(utimensat(AT_FDCWD, FILEERR, tptr, 0) == -1);
+}
+
+ATF_TC(utimensat_fderr1);
+ATF_TC_HEAD(utimensat_fderr1, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that utimensat fail with bad path");
+}
+ATF_TC_BODY(utimensat_fderr1, tc)
+{
+ int dfd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(utimensat(dfd, FILEERR, tptr, 0) == -1);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(utimensat_fderr2);
+ATF_TC_HEAD(utimensat_fderr2, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that utimensat fails with bad fdat");
+}
+ATF_TC_BODY(utimensat_fderr2, tc)
+{
+ int dfd;
+ int fd;
+ char cwd[MAXPATHLEN];
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE((dfd = open(getcwd(cwd, MAXPATHLEN), O_RDONLY, 0)) != -1);
+ ATF_REQUIRE(utimensat(dfd, BASEFILE, tptr, 0) == -1);
+ ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(utimensat_fderr3);
+ATF_TC_HEAD(utimensat_fderr3, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that utimensat fails with fd as -1");
+}
+ATF_TC_BODY(utimensat_fderr3, tc)
+{
+ int fd;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+ ATF_REQUIRE(close(fd) == 0);
+
+ ATF_REQUIRE(utimensat(-1, FILE, tptr, 0) == -1);
+}
+
+ATF_TC(utimensat_fdlink);
+ATF_TC_HEAD(utimensat_fdlink, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "See that utimensat works on symlink");
+}
+ATF_TC_BODY(utimensat_fdlink, tc)
+{
+ int dfd;
+ struct stat st;
+
+ ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+ ATF_REQUIRE(symlink(FILE, LINK) == 0); /* NB: FILE does not exists */
+
+ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
+
+ ATF_REQUIRE(utimensat(dfd, BASELINK, tptr, 0) == -1);
+ ATF_REQUIRE(errno = ENOENT);
+
+ ATF_REQUIRE(utimensat(dfd, BASELINK, tptr, AT_SYMLINK_NOFOLLOW) == 0);
+
+ ATF_REQUIRE(close(dfd) == 0);
+
+ ATF_REQUIRE(lstat(LINK, &st) == 0);
+ ATF_REQUIRE(st.st_atimespec.tv_sec == tptr[0].tv_sec);
+ ATF_REQUIRE(st.st_atimespec.tv_nsec == tptr[0].tv_nsec);
+ ATF_REQUIRE(st.st_mtimespec.tv_sec == tptr[1].tv_sec);
+ ATF_REQUIRE(st.st_mtimespec.tv_nsec == tptr[1].tv_nsec);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, utimensat_fd);
+ ATF_TP_ADD_TC(tp, utimensat_fdcwd);
+ ATF_TP_ADD_TC(tp, utimensat_fdcwderr);
+ ATF_TP_ADD_TC(tp, utimensat_fderr1);
+ ATF_TP_ADD_TC(tp, utimensat_fderr2);
+ ATF_TP_ADD_TC(tp, utimensat_fderr3);
+ ATF_TP_ADD_TC(tp, utimensat_fdlink);
+
+ return atf_no_error();
+}