Index: stable/10/contrib/netbsd-tests/lib/libc/c063/t_faccessat.c =================================================================== --- stable/10/contrib/netbsd-tests/lib/libc/c063/t_faccessat.c (revision 291869) +++ stable/10/contrib/netbsd-tests/lib/libc/c063/t_faccessat.c (revision 291870) @@ -1,188 +1,191 @@ /* $NetBSD: t_faccessat.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 __RCSID("$NetBSD: t_faccessat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $"); #include #include #include #include #include #include #include #include #include +#ifdef __FreeBSD__ +#include +#endif #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); #ifdef __FreeBSD__ atf_tc_expect_fail("Depends on non-standard behavior not mentioned in POSIX.1-2008"); #endif 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(); } Index: stable/10/contrib/netbsd-tests/lib/libc/c063/t_openat.c =================================================================== --- stable/10/contrib/netbsd-tests/lib/libc/c063/t_openat.c (revision 291869) +++ stable/10/contrib/netbsd-tests/lib/libc/c063/t_openat.c (revision 291870) @@ -1,165 +1,168 @@ /* $NetBSD: t_openat.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 __RCSID("$NetBSD: t_openat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $"); #include #include #include #include #include #include #include #include #include +#ifdef __FreeBSD__ +#include +#endif #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(); } Index: stable/10/contrib/netbsd-tests/lib/libc/c063/t_readlinkat.c =================================================================== --- stable/10/contrib/netbsd-tests/lib/libc/c063/t_readlinkat.c (revision 291869) +++ stable/10/contrib/netbsd-tests/lib/libc/c063/t_readlinkat.c (revision 291870) @@ -1,157 +1,160 @@ /* $NetBSD: t_readlinkat.c,v 1.3 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 __RCSID("$NetBSD: t_readlinkat.c,v 1.3 2013/03/17 04:46:06 jmmv Exp $"); #include #include #include #include #include #include #include #include #include +#ifdef __FreeBSD__ +#include +#endif #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(); } Index: stable/10/contrib/netbsd-tests/lib/libc/c063/t_unlinkat.c =================================================================== --- stable/10/contrib/netbsd-tests/lib/libc/c063/t_unlinkat.c (revision 291869) +++ stable/10/contrib/netbsd-tests/lib/libc/c063/t_unlinkat.c (revision 291870) @@ -1,176 +1,179 @@ /* $NetBSD: t_unlinkat.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 __RCSID("$NetBSD: t_unlinkat.c,v 1.2 2013/03/17 04:46:06 jmmv Exp $"); #include #include #include #include #include #include #include #include #include +#ifdef __FreeBSD__ +#include +#endif #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(); } Index: stable/10/lib/libc/tests/Makefile.netbsd-tests =================================================================== --- stable/10/lib/libc/tests/Makefile.netbsd-tests (revision 291869) +++ stable/10/lib/libc/tests/Makefile.netbsd-tests (revision 291870) @@ -1,7 +1,9 @@ # $FreeBSD$ OBJTOP?= ${.OBJDIR:H:H:H:H} SRCTOP?= ${.CURDIR:H:H:H:H} TESTSRC?= ${SRCTOP}/contrib/netbsd-tests/lib/libc/${.CURDIR:T} +WARNS?= 2 + .include Index: stable/10/lib/libc/tests/stdio/fmemopen2_test.c =================================================================== --- stable/10/lib/libc/tests/stdio/fmemopen2_test.c (revision 291869) +++ stable/10/lib/libc/tests/stdio/fmemopen2_test.c (revision 291870) @@ -1,286 +1,285 @@ /*- Copyright (C) 2013 Pietro Cerutti 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 AUTHOR 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 AUTHOR 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. */ /* * Test basic FILE * functions (fread, fwrite, fseek, fclose) against * a FILE * retrieved using fmemopen() */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include ATF_TC_WITHOUT_HEAD(test_preexisting); ATF_TC_BODY(test_preexisting, tc) { /* Use a pre-existing buffer. */ char buf[512]; char buf2[512]; char str[] = "Test writing some stuff"; char str2[] = "AAAAAAAAA"; char str3[] = "AAAA writing some stuff"; FILE *fp; size_t nofw, nofr; int rc; /* Open a FILE * using fmemopen. */ fp = fmemopen(buf, sizeof(buf), "w"); ATF_REQUIRE(fp != NULL); /* Write to the buffer. */ nofw = fwrite(str, 1, sizeof(str), fp); ATF_REQUIRE(nofw == sizeof(str)); /* Close the FILE *. */ rc = fclose(fp); ATF_REQUIRE(rc == 0); /* Re-open the FILE * to read back the data. */ fp = fmemopen(buf, sizeof(buf), "r"); ATF_REQUIRE(fp != NULL); /* Read from the buffer. */ bzero(buf2, sizeof(buf2)); nofr = fread(buf2, 1, sizeof(buf2), fp); ATF_REQUIRE(nofr == sizeof(buf2)); /* * Since a write on a FILE * retrieved by fmemopen * will add a '\0' (if there's space), we can check * the strings for equality. */ ATF_REQUIRE(strcmp(str, buf2) == 0); /* Close the FILE *. */ rc = fclose(fp); ATF_REQUIRE(rc == 0); /* Now open a FILE * on the first 4 bytes of the string. */ fp = fmemopen(str, 4, "w"); ATF_REQUIRE(fp != NULL); /* * Try to write more bytes than we shoud, we'll get a short count (4). */ nofw = fwrite(str2, 1, sizeof(str2), fp); ATF_REQUIRE(nofw == 4); /* Close the FILE *. */ rc = fclose(fp); /* Check that the string was not modified after the first 4 bytes. */ ATF_REQUIRE(strcmp(str, str3) == 0); } ATF_TC_WITHOUT_HEAD(test_autoalloc); ATF_TC_BODY(test_autoalloc, tc) { /* Let fmemopen allocate the buffer. */ - char str[] = "A quick test"; FILE *fp; long pos; - size_t nofw, nofr, i; + size_t nofw, i; int rc; /* Open a FILE * using fmemopen. */ fp = fmemopen(NULL, 512, "w+"); ATF_REQUIRE(fp != NULL); /* fill the buffer */ for (i = 0; i < 512; i++) { nofw = fwrite("a", 1, 1, fp); ATF_REQUIRE(nofw == 1); } /* Get the current position into the stream. */ pos = ftell(fp); ATF_REQUIRE(pos == 512); /* Try to write past the end, we should get a short object count (0) */ nofw = fwrite("a", 1, 1, fp); ATF_REQUIRE(nofw == 0); /* Close the FILE *. */ rc = fclose(fp); ATF_REQUIRE(rc == 0); /* Open a FILE * using a wrong mode */ fp = fmemopen(NULL, 512, "r"); ATF_REQUIRE(fp == NULL); fp = fmemopen(NULL, 512, "w"); ATF_REQUIRE(fp == NULL); } ATF_TC_WITHOUT_HEAD(test_data_length); ATF_TC_BODY(test_data_length, tc) { /* * Here we test that a read operation doesn't go past the end of the * data actually written, and that a SEEK_END seeks from the end of the * data, not of the whole buffer. */ FILE *fp; char buf[512] = {'\0'}; char str[] = "Test data length. "; char str2[] = "Do we have two sentences?"; char str3[sizeof(str) + sizeof(str2) -1]; long pos; size_t nofw, nofr; int rc; /* Open a FILE * for updating our buffer. */ fp = fmemopen(buf, sizeof(buf), "w+"); ATF_REQUIRE(fp != NULL); /* Write our string into the buffer. */ nofw = fwrite(str, 1, sizeof(str), fp); ATF_REQUIRE(nofw == sizeof(str)); /* Now seek to the end and check that ftell gives us sizeof(str). */ rc = fseek(fp, 0, SEEK_END); ATF_REQUIRE(rc == 0); pos = ftell(fp); ATF_REQUIRE(pos == sizeof(str)); /* Close the FILE *. */ rc = fclose(fp); ATF_REQUIRE(rc == 0); /* Reopen the buffer for appending. */ fp = fmemopen(buf, sizeof(buf), "a+"); ATF_REQUIRE(fp != NULL); /* We should now be writing after the first string. */ nofw = fwrite(str2, 1, sizeof(str2), fp); ATF_REQUIRE(nofw == sizeof(str2)); /* Rewind the FILE *. */ rc = fseek(fp, 0, SEEK_SET); ATF_REQUIRE(rc == 0); /* Make sure we're at the beginning. */ pos = ftell(fp); ATF_REQUIRE(pos == 0); /* Read the whole buffer. */ nofr = fread(str3, 1, sizeof(buf), fp); ATF_REQUIRE(nofr == sizeof(str3)); /* Make sure the two strings are there. */ ATF_REQUIRE(strncmp(str3, str, sizeof(str) - 1) == 0); ATF_REQUIRE(strncmp(str3 + sizeof(str) - 1, str2, sizeof(str2)) == 0); /* Close the FILE *. */ rc = fclose(fp); ATF_REQUIRE(rc == 0); } ATF_TC_WITHOUT_HEAD(test_binary); ATF_TC_BODY(test_binary, tc) { /* * Make sure that NULL bytes are never appended when opening a buffer * in binary mode. */ FILE *fp; char buf[20]; char str[] = "Test"; size_t nofw; int rc, i; /* Pre-fill the buffer. */ memset(buf, 'A', sizeof(buf)); /* Open a FILE * in binary mode. */ fp = fmemopen(buf, sizeof(buf), "w+b"); ATF_REQUIRE(fp != NULL); /* Write some data into it. */ nofw = fwrite(str, 1, strlen(str), fp); ATF_REQUIRE(nofw == strlen(str)); /* Make sure that the buffer doesn't contain any NULL bytes. */ for (i = 0; i < sizeof(buf); i++) ATF_REQUIRE(buf[i] != '\0'); /* Close the FILE *. */ rc = fclose(fp); ATF_REQUIRE(rc == 0); } ATF_TC_WITHOUT_HEAD(test_append_binary_pos); ATF_TC_BODY(test_append_binary_pos, tc) { /* * For compatibility with other implementations (glibc), we set the * position to 0 when opening an automatically allocated binary stream * for appending. */ FILE *fp; fp = fmemopen(NULL, 16, "ab+"); ATF_REQUIRE(ftell(fp) == 0L); fclose(fp); /* Make sure that a pre-allocated buffer behaves correctly. */ char buf[] = "Hello"; fp = fmemopen(buf, sizeof(buf), "ab+"); ATF_REQUIRE(ftell(fp) == strlen(buf)); fclose(fp); } ATF_TC_WITHOUT_HEAD(test_size_0); ATF_TC_BODY(test_size_0, tc) { /* POSIX mandates that we return EINVAL if size is 0. */ FILE *fp; fp = fmemopen(NULL, 0, "r+"); ATF_REQUIRE(fp == NULL); ATF_REQUIRE(errno == EINVAL); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, test_autoalloc); ATF_TP_ADD_TC(tp, test_preexisting); ATF_TP_ADD_TC(tp, test_data_length); ATF_TP_ADD_TC(tp, test_binary); ATF_TP_ADD_TC(tp, test_append_binary_pos); ATF_TP_ADD_TC(tp, test_size_0); return (atf_no_error()); } Index: stable/10/lib/libc/tests/stdio/getdelim_test.c =================================================================== --- stable/10/lib/libc/tests/stdio/getdelim_test.c (revision 291869) +++ stable/10/lib/libc/tests/stdio/getdelim_test.c (revision 291870) @@ -1,239 +1,238 @@ /*- * Copyright (c) 2009 David Schultz * All rights reserved. * * 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 AUTHOR 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 AUTHOR 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 __FBSDID("$FreeBSD$"); #define _WITH_GETLINE #include #include #include #include #include #define CHUNK_MAX 10 /* The assertions depend on this string. */ char apothegm[] = "All work and no play\0 makes Jack a dull boy.\n"; /* * This is a neurotic reader function designed to give getdelim() a * hard time. It reads through the string `apothegm' and returns a * random number of bytes up to the requested length. */ static int _reader(void *cookie, char *buf, int len) { size_t *offp = cookie; size_t r; r = random() % CHUNK_MAX + 1; if (len > r) len = r; if (len > sizeof(apothegm) - *offp) len = sizeof(apothegm) - *offp; memcpy(buf, apothegm + *offp, len); *offp += len; return (len); } static FILE * mkfilebuf(void) { size_t *offp; offp = malloc(sizeof(*offp)); /* XXX leak */ *offp = 0; return (fropen(offp, _reader)); } ATF_TC_WITHOUT_HEAD(getline_basic); ATF_TC_BODY(getline_basic, tc) { FILE *fp; char *line; size_t linecap; int i; srandom(0); /* * Test multiple times with different buffer sizes * and different _reader() return values. */ errno = 0; for (i = 0; i < 8; i++) { fp = mkfilebuf(); linecap = i; line = malloc(i); /* First line: the full apothegm */ ATF_REQUIRE(getline(&line, &linecap, fp) == sizeof(apothegm) - 1); ATF_REQUIRE(memcmp(line, apothegm, sizeof(apothegm)) == 0); ATF_REQUIRE(linecap >= sizeof(apothegm)); /* Second line: the NUL terminator following the newline */ ATF_REQUIRE(getline(&line, &linecap, fp) == 1); ATF_REQUIRE(line[0] == '\0' && line[1] == '\0'); /* Third line: EOF */ line[0] = 'X'; ATF_REQUIRE(getline(&line, &linecap, fp) == -1); ATF_REQUIRE(line[0] == '\0'); free(line); line = NULL; ATF_REQUIRE(feof(fp)); ATF_REQUIRE(!ferror(fp)); fclose(fp); } ATF_REQUIRE(errno == 0); } ATF_TC_WITHOUT_HEAD(stream_error); ATF_TC_BODY(stream_error, tc) { - FILE *fp; char *line; size_t linecap; /* Make sure read errors are handled properly. */ line = NULL; linecap = 0; errno = 0; ATF_REQUIRE(getline(&line, &linecap, stdout) == -1); ATF_REQUIRE(errno == EBADF); errno = 0; ATF_REQUIRE(getdelim(&line, &linecap, 'X', stdout) == -1); ATF_REQUIRE(errno == EBADF); ATF_REQUIRE(ferror(stdout)); } ATF_TC_WITHOUT_HEAD(invalid_params); ATF_TC_BODY(invalid_params, tc) { FILE *fp; char *line; size_t linecap; /* Make sure NULL linep or linecapp pointers are handled. */ fp = mkfilebuf(); ATF_REQUIRE(getline(NULL, &linecap, fp) == -1); ATF_REQUIRE(errno == EINVAL); ATF_REQUIRE(getline(&line, NULL, fp) == -1); ATF_REQUIRE(errno == EINVAL); ATF_REQUIRE(ferror(fp)); fclose(fp); } ATF_TC_WITHOUT_HEAD(eof); ATF_TC_BODY(eof, tc) { FILE *fp; char *line; size_t linecap; /* Make sure getline() allocates memory as needed if fp is at EOF. */ errno = 0; fp = mkfilebuf(); while (!feof(fp)) /* advance to EOF; can't fseek this stream */ getc(fp); line = NULL; linecap = 0; printf("getline\n"); ATF_REQUIRE(getline(&line, &linecap, fp) == -1); ATF_REQUIRE(line[0] == '\0'); ATF_REQUIRE(linecap > 0); ATF_REQUIRE(errno == 0); printf("feof\n"); errno = 0; ATF_REQUIRE(feof(fp)); ATF_REQUIRE(!ferror(fp)); fclose(fp); } ATF_TC_WITHOUT_HEAD(nul); ATF_TC_BODY(nul, tc) { FILE *fp; char *line; size_t linecap, n; errno = 0; line = NULL; linecap = 0; /* Make sure a NUL delimiter works. */ fp = mkfilebuf(); n = strlen(apothegm); printf("getdelim\n"); ATF_REQUIRE(getdelim(&line, &linecap, '\0', fp) == n + 1); ATF_REQUIRE(strcmp(line, apothegm) == 0); ATF_REQUIRE(line[n + 1] == '\0'); ATF_REQUIRE(linecap > n + 1); n = strlen(apothegm + n + 1); printf("getdelim 2\n"); ATF_REQUIRE(getdelim(&line, &linecap, '\0', fp) == n + 1); ATF_REQUIRE(line[n + 1] == '\0'); ATF_REQUIRE(linecap > n + 1); ATF_REQUIRE(errno == 0); ATF_REQUIRE(!ferror(fp)); fclose(fp); } ATF_TC_WITHOUT_HEAD(empty_NULL_buffer); ATF_TC_BODY(empty_NULL_buffer, tc) { FILE *fp; char *line; size_t linecap; /* Make sure NULL *linep and zero *linecapp are handled. */ fp = mkfilebuf(); free(line); line = NULL; linecap = 42; ATF_REQUIRE(getline(&line, &linecap, fp) == sizeof(apothegm) - 1); ATF_REQUIRE(memcmp(line, apothegm, sizeof(apothegm)) == 0); fp = mkfilebuf(); free(line); line = malloc(100); linecap = 0; ATF_REQUIRE(getline(&line, &linecap, fp) == sizeof(apothegm) - 1); ATF_REQUIRE(memcmp(line, apothegm, sizeof(apothegm)) == 0); free(line); ATF_REQUIRE(!ferror(fp)); fclose(fp); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, getline_basic); ATF_TP_ADD_TC(tp, stream_error); ATF_TP_ADD_TC(tp, eof); ATF_TP_ADD_TC(tp, invalid_params); ATF_TP_ADD_TC(tp, nul); ATF_TP_ADD_TC(tp, empty_NULL_buffer); return (atf_no_error()); } Index: stable/10/lib/libc/tests/stdio/perror_test.c =================================================================== --- stable/10/lib/libc/tests/stdio/perror_test.c (revision 291869) +++ stable/10/lib/libc/tests/stdio/perror_test.c (revision 291870) @@ -1,107 +1,107 @@ /*- * Copyright (c) 2002 Tim J. Robbins * All rights reserved. * * 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 AUTHOR 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 AUTHOR 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. */ /* * Test program for perror() as specified by IEEE Std. 1003.1-2001 and * ISO/IEC 9899:1999. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include static char tmpfil[PATH_MAX]; ATF_TC_WITHOUT_HEAD(perror_test); ATF_TC_BODY(perror_test, tc) { - char buf[512], lbuf[512]; + char lbuf[512]; int i; char *s; strcpy(tmpfil, "perror.XXXXXXXX"); ATF_REQUIRE(mkstemp(tmpfil) >= 0); /* Reopen stderr on a file descriptor other than 2. */ fclose(stderr); for (i = 0; i < 3; i++) dup(0); ATF_REQUIRE(freopen(tmpfil, "r+", stderr) != NULL); /* * Test that perror() doesn't call strerror() (4.4BSD bug), * the two ways of omitting a program name, and the formatting when * a program name is specified. */ s = strerror(ENOENT); ATF_REQUIRE_MSG(strcmp(s, "No such file or directory") == 0, "message obtained was: %s", s); errno = EPERM; perror(NULL); perror(""); perror("perror_test"); ATF_REQUIRE_MSG(strcmp(s, "No such file or directory") == 0, "message obtained was: %s", s); /* * Read it back to check... */ rewind(stderr); s = fgets(lbuf, sizeof(lbuf), stderr); ATF_REQUIRE(s != NULL); ATF_REQUIRE_MSG(strcmp(s, "Operation not permitted\n") == 0, "message obtained was: %s", s); s = fgets(lbuf, sizeof(lbuf), stderr); ATF_REQUIRE(s != NULL); ATF_REQUIRE_MSG(strcmp(s, "Operation not permitted\n") == 0, "message obtained was: %s", s); s = fgets(lbuf, sizeof(lbuf), stderr); ATF_REQUIRE(s != NULL); ATF_REQUIRE_MSG( strcmp(s, "perror_test: Operation not permitted\n") == 0, "message obtained was: %s", s); s = fgets(lbuf, sizeof(lbuf), stderr); ATF_REQUIRE(s == NULL); fclose(stderr); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, perror_test); return (atf_no_error()); } Index: stable/10/lib/libc/tests/stdio/scanfloat_test.c =================================================================== --- stable/10/lib/libc/tests/stdio/scanfloat_test.c (revision 291869) +++ stable/10/lib/libc/tests/stdio/scanfloat_test.c (revision 291870) @@ -1,325 +1,316 @@ /*- * Copyright (C) 2003, 2005 David Schultz * All rights reserved. * * 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 AUTHOR 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 AUTHOR 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. */ /* * Test for scanf() floating point formats. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #define eq(type, a, b) _eq(type##_EPSILON, (a), (b)) static int _eq(long double epsilon, long double a, long double b) { long double delta; delta = fabsl(a - b); return (delta <= epsilon); } ATF_TC_WITHOUT_HEAD(normalized_numbers); ATF_TC_BODY(normalized_numbers, tc) { char buf[128]; long double ld = 0.0; double d = 0.0; float f = 0.0; - char *endp; buf[0] = '\0'; ATF_REQUIRE(setlocale(LC_NUMERIC, "")); sscanf("3.141592", "%e", &f); ATF_REQUIRE(eq(FLT, f, 3.141592)); sscanf("3.141592653589793", "%lf", &d); ATF_REQUIRE(eq(DBL, d, 3.141592653589793)); sscanf("1.234568e+06", "%E", &f); ATF_REQUIRE(eq(FLT, f, 1.234568e+06)); sscanf("-1.234568e6", "%lF", &d); ATF_REQUIRE(eq(DBL, d, -1.234568e6)); sscanf("+1.234568e-52", "%LG", &ld); ATF_REQUIRE(eq(LDBL, ld, 1.234568e-52L)); sscanf("0.1", "%la", &d); ATF_REQUIRE(eq(DBL, d, 0.1)); sscanf("00.2", "%lA", &d); ATF_REQUIRE(eq(DBL, d, 0.2)); sscanf("123456", "%5le%s", &d, buf); ATF_REQUIRE(eq(DBL, d, 12345.)); ATF_REQUIRE(strcmp(buf, "6") == 0); sscanf("1.0Q", "%*5le%s", buf); ATF_REQUIRE(strcmp(buf, "Q") == 0); sscanf("-1.23e", "%e%s", &f, buf); ATF_REQUIRE(eq(FLT, f, -1.23)); ATF_REQUIRE(strcmp(buf, "e") == 0); sscanf("1.25e+", "%le%s", &d, buf); ATF_REQUIRE(eq(DBL, d, 1.25)); ATF_REQUIRE(strcmp(buf, "e+") == 0); sscanf("1.23E4E5", "%le%s", &d, buf); ATF_REQUIRE(eq(DBL, d, 1.23e4)); ATF_REQUIRE(strcmp(buf, "E5") == 0); sscanf("12e6", "%le", &d); ATF_REQUIRE(eq(DBL, d, 12e6)); sscanf("1.a", "%le%s", &d, buf); ATF_REQUIRE(eq(DBL, d, 1.0)); ATF_REQUIRE(strcmp(buf, "a") == 0); sscanf(".0p4", "%le%s", &d, buf); ATF_REQUIRE(eq(DBL, d, 0.0)); ATF_REQUIRE(strcmp(buf, "p4") == 0); d = 0.25; ATF_REQUIRE(sscanf(".", "%le", &d) == 0); ATF_REQUIRE(d == 0.25); sscanf("0x08", "%le", &d); ATF_REQUIRE(d == 0x8p0); sscanf("0x90a.bcdefP+09a", "%le%s", &d, buf); ATF_REQUIRE(d == 0x90a.bcdefp+09); ATF_REQUIRE(strcmp(buf, "a") == 0); #if (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) sscanf("3.14159265358979323846", "%Lg", &ld); ATF_REQUIRE(eq(LDBL, ld, 3.14159265358979323846L)); sscanf(" 0X.0123456789abcdefffp-3g", "%Le%s", &ld, buf); ATF_REQUIRE(ld == 0x0.0123456789abcdefffp-3L); ATF_REQUIRE(strcmp(buf, "g") == 0); #endif sscanf("0xg", "%le%s", &d, buf); ATF_REQUIRE(d == 0.0); ATF_REQUIRE(strcmp(buf, "xg") == 0); ATF_REQUIRE(setlocale(LC_NUMERIC, "ru_RU.ISO8859-5")); /* decimalpoint==, */ sscanf("1.23", "%le%s", &d, buf); ATF_REQUIRE(d == 1.0); ATF_REQUIRE(strcmp(buf, ".23") == 0); sscanf("1,23", "%le", &d); ATF_REQUIRE(d == 1.23); ATF_REQUIRE(setlocale(LC_NUMERIC, "")); } ATF_TC_WITHOUT_HEAD(infinities_and_nans); ATF_TC_BODY(infinities_and_nans, tc) { char buf[128]; long double ld = 0.0; double d = 0.0; float f = 0.0; - char *endp; ATF_REQUIRE(setlocale(LC_NUMERIC, "C")); sscanf("-Inf", "%le", &d); ATF_REQUIRE(d < 0.0 && isinf(d)); sscanf("iNfInItY and beyond", "%le%s", &d, buf); ATF_REQUIRE(d > 0.0 && isinf(d)); ATF_REQUIRE(strcmp(buf, " and beyond")); sscanf("NaN", "%le", &d); ATF_REQUIRE(isnan(d)); sscanf("NAN(123Y", "%le%s", &d, buf); ATF_REQUIRE(isnan(d)); ATF_REQUIRE(strcmp(buf, "(123Y") == 0); sscanf("nan(f00f)plugh", "%le%s", &d, buf); ATF_REQUIRE(isnan(d)); ATF_REQUIRE(strcmp(buf, "plugh") == 0); sscanf("-nan", "%le", &d); ATF_REQUIRE(isnan(d)); /* Only quiet NaNs should be returned. */ sscanf("NaN", "%e", &f); sscanf("nan", "%le", &d); sscanf("nan", "%Le", &ld); feclearexcept(FE_ALL_EXCEPT); ATF_REQUIRE(f != f); ATF_REQUIRE(d != d); ATF_REQUIRE(ld != ld); ATF_REQUIRE(fetestexcept(FE_INVALID) == 0); sscanf("nan(1234)", "%e", &f); sscanf("nan(1234)", "%le", &d); sscanf("nan(1234)", "%Le", &ld); feclearexcept(FE_ALL_EXCEPT); ATF_REQUIRE(f != f); ATF_REQUIRE(d != d); ATF_REQUIRE(ld != ld); /* POSIX says we should only generate quiet NaNs. */ ATF_REQUIRE(fetestexcept(FE_INVALID) == 0); } ATF_TC_WITHOUT_HEAD(rounding_tests); ATF_TC_BODY(rounding_tests, tc) { - char buf[128]; long double ld = 0.0; double d = 0.0; - float f = 0.0; - char *endp; ATF_REQUIRE(setlocale(LC_NUMERIC, "C")); fesetround(FE_DOWNWARD); sscanf("1.999999999999999999999999999999999", "%le", &d); ATF_REQUIRE(d < 2.0); sscanf("0x1.ffffffffffffffp0", "%le", &d); ATF_REQUIRE(d < 2.0); sscanf("1.999999999999999999999999999999999", "%Le", &ld); ATF_REQUIRE(ld < 2.0); sscanf("1.0571892669084007", "%le", &d); ATF_REQUIRE(d == 0x1.0ea3f4af0dc59p0); sscanf("-1.0571892669084007", "%le", &d); ATF_REQUIRE(d == -0x1.0ea3f4af0dc5ap0); sscanf("1.0571892669084010", "%le", &d); ATF_REQUIRE(d == 0x1.0ea3f4af0dc5ap0); sscanf("0x1.23p-5000", "%le", &d); ATF_REQUIRE(d == 0.0); sscanf("0x1.2345678p-1050", "%le", &d); ATF_REQUIRE(d == 0x1.234567p-1050); fesetround(FE_UPWARD); sscanf("1.0571892669084007", "%le", &d); ATF_REQUIRE(d == 0x1.0ea3f4af0dc5ap0); sscanf("-1.0571892669084007", "%le", &d); ATF_REQUIRE(d == -0x1.0ea3f4af0dc59p0); sscanf("1.0571892669084010", "%le", &d); ATF_REQUIRE(d == 0x1.0ea3f4af0dc5bp0); sscanf("0x1.23p-5000", "%le", &d); ATF_REQUIRE(d == 0x1p-1074); sscanf("0x1.2345678p-1050", "%le", &d); ATF_REQUIRE(d == 0x1.234568p-1050); fesetround(FE_TOWARDZERO); sscanf("1.0571892669084007", "%le", &d); ATF_REQUIRE(d == 0x1.0ea3f4af0dc59p0); sscanf("-1.0571892669084007", "%le", &d); ATF_REQUIRE(d == -0x1.0ea3f4af0dc59p0); sscanf("1.0571892669084010", "%le", &d); ATF_REQUIRE(d == 0x1.0ea3f4af0dc5ap0); sscanf("0x1.23p-5000", "%le", &d); ATF_REQUIRE(d == 0.0); sscanf("0x1.2345678p-1050", "%le", &d); ATF_REQUIRE(d == 0x1.234567p-1050); fesetround(FE_TONEAREST); /* 1.0571892669084007 is slightly closer to 0x1.0ea3f4af0dc59p0 */ sscanf("1.0571892669084007", "%le", &d); ATF_REQUIRE(d == 0x1.0ea3f4af0dc59p0); sscanf("-1.0571892669084007", "%le", &d); ATF_REQUIRE(d == -0x1.0ea3f4af0dc59p0); sscanf("1.0571892669084010", "%le", &d); ATF_REQUIRE(d == 0x1.0ea3f4af0dc5bp0); /* strtod() should round small numbers to 0. */ sscanf("0x1.23p-5000", "%le", &d); ATF_REQUIRE(d == 0.0); /* Extra digits in a denormal shouldn't break anything. */ sscanf("0x1.2345678p-1050", "%le", &d); ATF_REQUIRE(d == 0x1.234568p-1050); } ATF_TC_WITHOUT_HEAD(strtod); ATF_TC_BODY(strtod, tc) { - char buf[128]; - long double ld = 0.0; - double d = 0.0; - float f = 0.0; char *endp; ATF_REQUIRE(setlocale(LC_NUMERIC, "C")); ATF_REQUIRE(strtod("0xy", &endp) == 0); ATF_REQUIRE(strcmp("xy", endp) == 0); /* This used to cause an infinite loop and round the wrong way. */ fesetround(FE_DOWNWARD); ATF_REQUIRE(strtof("3.5e38", &endp) == FLT_MAX); ATF_REQUIRE(strtod("2e308", &endp) == DBL_MAX); fesetround(FE_UPWARD); ATF_REQUIRE(strtof("3.5e38", &endp) == INFINITY); ATF_REQUIRE(strtod("2e308", &endp) == INFINITY); fesetround(FE_TOWARDZERO); ATF_REQUIRE(strtof("3.5e38", &endp) == FLT_MAX); ATF_REQUIRE(strtod("2e308", &endp) == DBL_MAX); fesetround(FE_TONEAREST); ATF_REQUIRE(strtof("3.5e38", &endp) == INFINITY); ATF_REQUIRE(strtod("2e308", &endp) == INFINITY); } ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, normalized_numbers); ATF_TP_ADD_TC(tp, infinities_and_nans); ATF_TP_ADD_TC(tp, rounding_tests); ATF_TP_ADD_TC(tp, strtod); return (atf_no_error()); } Index: stable/10 =================================================================== --- stable/10 (revision 291869) +++ stable/10 (revision 291870) Property changes on: stable/10 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r283801,290846,290851,290860