1 /*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 */
27
28 #include <sys/types.h>
29 #include <sys/fcntl.h>
30 #include <errno.h>
31 #include <string.h>
32 #include <signal.h>
33 #include "test.h"
34
35 static void setup(void);
36 static void cleanup(void);
37
38 char *TCID = "open03";
39 int TST_TOTAL = 1;
40
41 static char fname[255];
42 static int fd;
43
main(int ac,char ** av)44 int main(int ac, char **av)
45 {
46 int lc;
47
48 tst_parse_opts(ac, av, NULL, NULL);
49
50 setup();
51
52 for (lc = 0; TEST_LOOPING(lc); lc++) {
53 tst_count = 0;
54
55 TEST(open(fname, O_RDWR | O_CREAT, 0700));
56 fd = TEST_RETURN;
57
58 if (TEST_RETURN == -1) {
59 tst_resm(TFAIL | TTERRNO,
60 "open(%s,O_RDWR|O_CREAT,0700) failed", fname);
61 } else {
62 tst_resm(TPASS,
63 "open(%s, O_RDWR|O_CREAT,0700) returned %ld",
64 fname, TEST_RETURN);
65
66 if (close(fd) == -1)
67 tst_brkm(TBROK | TERRNO, cleanup,
68 "close(%s) failed", fname);
69 else if (unlink(fname) == -1)
70 tst_brkm(TBROK | TERRNO, cleanup,
71 "unlink(%s) failed", fname);
72 }
73 }
74
75 cleanup();
76 tst_exit();
77 }
78
setup(void)79 static void setup(void)
80 {
81 tst_sig(NOFORK, DEF_HANDLER, cleanup);
82
83 TEST_PAUSE;
84
85 tst_tmpdir();
86
87 sprintf(fname, "tfile_%d", getpid());
88 }
89
cleanup(void)90 static void cleanup(void)
91 {
92 tst_rmdir();
93 }
94