• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_GETFD argument.
36   */
37 
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 #include <fcntl.h>
41 #include <unistd.h>
42 #include <errno.h>
43 #include <stdio.h>
44 
45 #include "tst_test.h"
46 
47 static char fname[255];
48 static int fd;
49 
verify_fcntl(void)50 static void verify_fcntl(void)
51 {
52 	TEST(fcntl(fd, F_GETFD, 0));
53 
54 	if (TEST_RETURN == -1) {
55 		tst_res(TFAIL | TTERRNO, "fcntl(%s, F_GETFD, 0) failed",
56 			fname);
57 		return;
58 	}
59 
60 	tst_res(TPASS, "fcntl(%s, F_GETFD, 0) returned %ld",
61 		fname, TEST_RETURN);
62 }
63 
setup(void)64 static void setup(void)
65 {
66 	sprintf(fname, "fcntl03_%d", getpid());
67 	fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0700);
68 }
69 
cleanup(void)70 static void cleanup(void)
71 {
72 	if (fd > 0)
73 		SAFE_CLOSE(fd);
74 }
75 
76 static struct tst_test test = {
77 	.tid = "fcntl03",
78 	.needs_tmpdir = 1,
79 	.test_all = verify_fcntl,
80 	.setup = setup,
81 	.cleanup = cleanup,
82 };
83