1 /*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3 * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 *
13 * Further, this software is distributed without any warranty that it is
14 * free of the rightful claim of any third person regarding infringement
15 * or the like. Any license provided herein, whether implied or
16 * otherwise, applies only to this software file. Patent licenses, if
17 * any, provided herein do not apply to combinations of this program with
18 * other software, or any other product whatsoever.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 *
24 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
25 * Mountain View, CA 94043, or:
26 *
27 * http://www.sgi.com
28 *
29 * For further information regarding this notice, see:
30 *
31 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
32 *
33 */
34 /*
35 * Basic test for fcntl(2) using F_GETFL argument.
36 */
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <fcntl.h>
40 #include <unistd.h>
41 #include <errno.h>
42 #include <stdio.h>
43
44 #include "tst_test.h"
45
46 static int fd;
47 static char fname[255];
48
verify_fcntl(void)49 static void verify_fcntl(void)
50 {
51 TEST(fcntl(fd, F_GETFL, 0));
52
53 if (TEST_RETURN == -1) {
54 tst_res(TFAIL | TTERRNO, "fcntl(%s, F_GETFL, 0) failed",
55 fname);
56 return;
57 }
58
59 if ((TEST_RETURN & O_ACCMODE) != O_RDWR) {
60 tst_res(TFAIL, "fcntl(%s, F_GETFL, 0) returned wrong "
61 "access mode %li, expected %i", fname,
62 TEST_RETURN & O_ACCMODE, O_RDWR);
63 return;
64 }
65
66 tst_res(TPASS, "fcntl(%s, F_GETFL, 0) returned %lx",
67 fname, TEST_RETURN);
68 }
69
setup(void)70 static void setup(void)
71 {
72 sprintf(fname, "fcntl04_%d", getpid());
73 fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0700);
74 }
75
cleanup(void)76 static void cleanup(void)
77 {
78 if (fd > 0)
79 SAFE_CLOSE(fd);
80 }
81
82 static struct tst_test test = {
83 .needs_tmpdir = 1,
84 .test_all = verify_fcntl,
85 .setup = setup,
86 .cleanup = cleanup,
87 };
88