xref: /minix3/tests/lib/libc/sys/t_posix_fallocate.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: t_posix_fallocate.c,v 1.1 2015/01/31 23:06:57 christos Exp $	*/
2*0a6a1f1dSLionel Sambuc 
3*0a6a1f1dSLionel Sambuc /*-
4*0a6a1f1dSLionel Sambuc  * Copyright 2015, Google Inc. All rights reserved.
5*0a6a1f1dSLionel Sambuc  *
6*0a6a1f1dSLionel Sambuc  * Redistribution and use in source and binary forms, with or without
7*0a6a1f1dSLionel Sambuc  * modification, are permitted provided that the following conditions
8*0a6a1f1dSLionel Sambuc  * are met:
9*0a6a1f1dSLionel Sambuc  *
10*0a6a1f1dSLionel Sambuc  *  * Redistributions of source code must retain the above copyright
11*0a6a1f1dSLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
12*0a6a1f1dSLionel Sambuc  *  * Redistributions in binary form must reproduce the above copyright
13*0a6a1f1dSLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
14*0a6a1f1dSLionel Sambuc  *    documentation and/or other materials provided with the distribution.
15*0a6a1f1dSLionel Sambuc  *  * Neither the name of Google nor the names of its contributors may
16*0a6a1f1dSLionel Sambuc  *    be used to endorse or promote products derived from this software
17*0a6a1f1dSLionel Sambuc  *    without specific prior written permission.
18*0a6a1f1dSLionel Sambuc  *
19*0a6a1f1dSLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20*0a6a1f1dSLionel Sambuc  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*0a6a1f1dSLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*0a6a1f1dSLionel Sambuc  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23*0a6a1f1dSLionel Sambuc  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*0a6a1f1dSLionel Sambuc  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*0a6a1f1dSLionel Sambuc  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*0a6a1f1dSLionel Sambuc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*0a6a1f1dSLionel Sambuc  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*0a6a1f1dSLionel Sambuc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*0a6a1f1dSLionel Sambuc  * POSSIBILITY OF SUCH DAMAGE.
30*0a6a1f1dSLionel Sambuc  */
31*0a6a1f1dSLionel Sambuc 
32*0a6a1f1dSLionel Sambuc #include <sys/cdefs.h>
33*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: t_posix_fallocate.c,v 1.1 2015/01/31 23:06:57 christos Exp $");
34*0a6a1f1dSLionel Sambuc 
35*0a6a1f1dSLionel Sambuc #include <atf-c.h>
36*0a6a1f1dSLionel Sambuc #include <errno.h>
37*0a6a1f1dSLionel Sambuc #include <fcntl.h>
38*0a6a1f1dSLionel Sambuc #include <unistd.h>
39*0a6a1f1dSLionel Sambuc 
40*0a6a1f1dSLionel Sambuc ATF_TC_WITHOUT_HEAD(ebadf);
ATF_TC_BODY(ebadf,tc)41*0a6a1f1dSLionel Sambuc ATF_TC_BODY(ebadf, tc)
42*0a6a1f1dSLionel Sambuc {
43*0a6a1f1dSLionel Sambuc 	int rc, saved;
44*0a6a1f1dSLionel Sambuc 
45*0a6a1f1dSLionel Sambuc 	errno = 1111;
46*0a6a1f1dSLionel Sambuc 	rc = posix_fallocate(-1, 0, 4096);
47*0a6a1f1dSLionel Sambuc 	saved = errno;
48*0a6a1f1dSLionel Sambuc 	if (rc == -1 && saved != 1111)
49*0a6a1f1dSLionel Sambuc 		atf_tc_fail("Should return error %s without setting errno.",
50*0a6a1f1dSLionel Sambuc 		    strerror(saved));
51*0a6a1f1dSLionel Sambuc 	if (rc != EBADF)
52*0a6a1f1dSLionel Sambuc 		atf_tc_fail("returned %s but expected %s.",
53*0a6a1f1dSLionel Sambuc 		    strerror(saved), strerror(EBADF));
54*0a6a1f1dSLionel Sambuc 	if (saved != 1111)
55*0a6a1f1dSLionel Sambuc 		atf_tc_fail("errno should be %d but got changed to %d.",
56*0a6a1f1dSLionel Sambuc 		    1111, saved);
57*0a6a1f1dSLionel Sambuc }
58*0a6a1f1dSLionel Sambuc 
ATF_TP_ADD_TCS(tp)59*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TCS(tp)
60*0a6a1f1dSLionel Sambuc {
61*0a6a1f1dSLionel Sambuc 	ATF_TP_ADD_TC(tp, ebadf);
62*0a6a1f1dSLionel Sambuc 	return atf_no_error();
63*0a6a1f1dSLionel Sambuc }
64