blob: 39f9471b457c8d7e798bdaad83ecfe593c1c3748 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
Cyril Hrubis3e04fd52014-06-02 18:28:49 +02003 * AUTHOR : William Roske
4 * CO-PILOT : Dave Fenner
plars865695b2001-08-27 22:15:12 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it would be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 *
14 * Further, this software is distributed without any warranty that it is
15 * free of the rightful claim of any third person regarding infringement
16 * or the like. Any license provided herein, whether implied or
17 * otherwise, applies only to this software file. Patent licenses, if
18 * any, provided herein do not apply to combinations of this program with
19 * other software, or any other product whatsoever.
20 *
21 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080022 * with this program; if not, write the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
plars865695b2001-08-27 22:15:12 +000024 *
25 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
26 * Mountain View, CA 94043, or:
27 *
28 * http://www.sgi.com
29 *
30 * For further information regarding this notice, see:
31 *
32 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
33 *
34 */
plars865695b2001-08-27 22:15:12 +000035
36#include <sys/types.h>
mridgedb639212005-01-04 21:04:11 +000037#include <fcntl.h>
38#include <unistd.h>
plars865695b2001-08-27 22:15:12 +000039#include <sys/stat.h>
40#include <errno.h>
41#include <string.h>
42#include <signal.h>
Cyril Hrubis3e04fd52014-06-02 18:28:49 +020043
plars865695b2001-08-27 22:15:12 +000044#include "test.h"
Cyril Hrubis3e04fd52014-06-02 18:28:49 +020045#include "safe_macros.h"
plars865695b2001-08-27 22:15:12 +000046
Cyril Hrubis3e04fd52014-06-02 18:28:49 +020047static void setup(void);
48static void cleanup(void);
plars865695b2001-08-27 22:15:12 +000049
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020050char *TCID = "fcntl08";
51int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000052
Cyril Hrubis3e04fd52014-06-02 18:28:49 +020053static int fd;
plars865695b2001-08-27 22:15:12 +000054
subrata_modak56207ce2009-03-23 13:35:39 +000055int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000056{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020057 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020058 const char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +000059
Garrett Cooperc737f2f2010-12-18 19:58:34 -080060 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
subrata_modak56207ce2009-03-23 13:35:39 +000061 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -080062
subrata_modak56207ce2009-03-23 13:35:39 +000063 setup();
plars865695b2001-08-27 22:15:12 +000064
subrata_modak56207ce2009-03-23 13:35:39 +000065 for (lc = 0; TEST_LOOPING(lc); lc++) {
plars865695b2001-08-27 22:15:12 +000066
Caspar Zhangd59a6592013-03-07 14:59:12 +080067 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000068
Cyril Hrubis3e04fd52014-06-02 18:28:49 +020069 TEST(fcntl(fd, F_SETFL, O_NDELAY | O_APPEND | O_NONBLOCK));
subrata_modakbdbaec52009-02-26 12:14:51 +000070
Cyril Hrubis3e04fd52014-06-02 18:28:49 +020071 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +080072 tst_resm(TFAIL | TTERRNO, "fcntl failed");
Cyril Hrubis3e04fd52014-06-02 18:28:49 +020073 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +020074 tst_resm(TPASS, "fcntl returned %ld",
75 TEST_RETURN);
subrata_modak56207ce2009-03-23 13:35:39 +000076 }
plars865695b2001-08-27 22:15:12 +000077
Garrett Cooper2c282152010-12-16 00:55:50 -080078 }
plars865695b2001-08-27 22:15:12 +000079
subrata_modak56207ce2009-03-23 13:35:39 +000080 cleanup();
Garrett Cooperc737f2f2010-12-18 19:58:34 -080081 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -080082}
plars865695b2001-08-27 22:15:12 +000083
Mike Frysingerc57fba52014-04-09 18:56:30 -040084void setup(void)
plars865695b2001-08-27 22:15:12 +000085{
Garrett Cooper2c282152010-12-16 00:55:50 -080086
subrata_modak56207ce2009-03-23 13:35:39 +000087 tst_sig(NOFORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +000088
subrata_modak56207ce2009-03-23 13:35:39 +000089 TEST_PAUSE;
plars865695b2001-08-27 22:15:12 +000090
subrata_modak56207ce2009-03-23 13:35:39 +000091 tst_tmpdir();
plars865695b2001-08-27 22:15:12 +000092
Cyril Hrubis3e04fd52014-06-02 18:28:49 +020093 fd = SAFE_OPEN(cleanup, "test_file", O_RDWR | O_CREAT, 0700);
Garrett Cooper2c282152010-12-16 00:55:50 -080094}
plars865695b2001-08-27 22:15:12 +000095
Mike Frysingerc57fba52014-04-09 18:56:30 -040096void cleanup(void)
plars865695b2001-08-27 22:15:12 +000097{
Garrett Cooperc737f2f2010-12-18 19:58:34 -080098 if (close(fd) == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +080099 tst_resm(TWARN | TERRNO, "close failed");
plars865695b2001-08-27 22:15:12 +0000100
subrata_modak56207ce2009-03-23 13:35:39 +0000101 tst_rmdir();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700102}