1 /*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 /*
21 * NAME
22 * fcntl13.c
23 *
24 * DESCRIPTION
25 * Testcase to test that fcntl() sets errno correctly.
26 *
27 * USAGE
28 * fcntl13
29 *
30 * HISTORY
31 * 07/2001 Ported by Wayne Boyer
32 *
33 * RESTRICTIONS
34 * NONE
35 */
36
37 #include <fcntl.h>
38 #include <errno.h>
39 #include "test.h"
40
41 #define F_BADCMD 99999
42
43 char *TCID = "fcntl13";
44 int TST_TOTAL = 1;
45
46 void setup(void);
47
main(int ac,char ** av)48 int main(int ac, char **av)
49 {
50 int lc;
51
52 struct flock flock;
53
54 tst_parse_opts(ac, av, NULL, NULL);
55
56 setup();
57
58 for (lc = 0; TEST_LOOPING(lc); lc++) {
59 tst_count = 0;
60
61 if (fcntl(1, F_BADCMD, 1) != -1)
62 tst_resm(TFAIL, "fcntl(2) failed to FAIL");
63 else if (errno != EINVAL)
64 tst_resm(TFAIL, "Expected EINVAL got %d", errno);
65 else
66 tst_resm(TPASS, "got EINVAL");
67
68 #ifndef UCLINUX
69 if (fcntl(1, F_SETLK, (void *)-1) != -1) {
70 tst_resm(TFAIL, "F_SETLK: fcntl(2) failed to FAIL");
71 } else if (errno != EFAULT) {
72 tst_resm(TFAIL, "F_SETLK: Expected EFAULT got %d",
73 errno);
74 } else {
75 tst_resm(TPASS, "F_SETLK: got EFAULT");
76 }
77
78 if (fcntl(1, F_SETLKW, (void *)-1) != -1) {
79 tst_resm(TFAIL, "F_SETLKW: fcntl(2) failed to FAIL");
80 } else if (errno != EFAULT) {
81 tst_resm(TFAIL, "F_SETLKW: Expected EFAULT got %d",
82 errno);
83 } else {
84 tst_resm(TPASS, "F_SETLKW: got EFAULT");
85 }
86
87 if (fcntl(1, F_GETLK, (void *)-1) != -1) {
88 tst_resm(TFAIL, "F_GETLK: fcntl(2) failed to FAIL");
89 } else if (errno != EFAULT) {
90 tst_resm(TFAIL, "F_GETLK: Expected EFAULT got %d",
91 errno);
92 } else {
93 tst_resm(TPASS, "F_GETLK: got EFAULT");
94 }
95
96 #else
97 tst_resm(TCONF, "Skip EFAULT on uClinux");
98 #endif
99 flock.l_whence = -1;
100 flock.l_type = F_WRLCK;
101 flock.l_start = 0L;
102 flock.l_len = 0L;
103
104 if (fcntl(1, F_SETLK, &flock) != -1)
105 tst_resm(TFAIL, "fcntl(2) failed to FAIL");
106 else if (errno != EINVAL)
107 tst_resm(TFAIL, "Expected EINVAL, got %d", errno);
108 else
109 tst_resm(TPASS, "got EINVAL");
110
111 if (fcntl(-1, F_GETLK, &flock) != -1)
112 tst_resm(TFAIL, "fcntl(2) failed to FAIL");
113 else if (errno != EBADF)
114 tst_resm(TFAIL, "Expected EBADF, got %d", errno);
115 else
116 tst_resm(TPASS, "got EBADFD");
117 }
118
119 tst_exit();
120 }
121
setup(void)122 void setup(void)
123 {
124 tst_sig(NOFORK, DEF_HANDLER, NULL);
125
126 TEST_PAUSE;
127 }
128