• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  *   Copyright (c) International Business Machines  Corp., 2002
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 /* ported from SPIE section2/filesuite/stream2.c, by Airong Zhang */
20 
21 /*======================================================================
22 	=================== TESTPLAN SEGMENT ===================
23 >KEYS:  < fseek() mknod() fopen()
24 >WHAT:  < 1)
25 >HOW:   < 1)
26 >BUGS:  <
27 ======================================================================*/
28 
29 #include <stdio.h>
30 #include <errno.h>
31 #include <fcntl.h>
32 #include <unistd.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include "test.h"
36 
37 char *TCID = "stream02";
38 int TST_TOTAL = 1;
39 int local_flag;
40 
41 #define PASSED 1
42 #define FAILED 0
43 
44 char progname[] = "stream02()";
45 char tempfile1[40] = "";
46 
47 /* XXX: add cleanup + setup. */
48 
49 /*--------------------------------------------------------------------*/
main(int ac,char * av[])50 int main(int ac, char *av[])
51 {
52 	FILE *stream;
53 	int fd;
54 	int lc;
55 
56 	/*
57 	 * parse standard options
58 	 */
59 	tst_parse_opts(ac, av, NULL, NULL);
60 
61 	local_flag = PASSED;
62 	tst_tmpdir();
63 
64 	for (lc = 0; TEST_LOOPING(lc); lc++) {
65 
66 		sprintf(tempfile1, "stream1.%d", getpid());
67 	/*--------------------------------------------------------------------*/
68 		//block0:
69 		if (mknod(tempfile1, (S_IFIFO | 0666), 0) != 0) {
70 			tst_resm(TFAIL, "mknod failed in block0: %s",
71 				 strerror(errno));
72 			local_flag = FAILED;
73 			goto block1;
74 		}
75 		if ((stream = fopen(tempfile1, "w+")) == NULL) {
76 			tst_resm(TFAIL, "fopen(%s) w+ failed for pipe file: %s",
77 				 tempfile1, strerror(errno));
78 			local_flag = FAILED;
79 		} else {
80 			fclose(stream);
81 		}
82 		if ((stream = fopen(tempfile1, "a+")) == NULL) {
83 			tst_resm(TFAIL, "fopen(%s) a+ failed: %s", tempfile1,
84 				 strerror(errno));
85 			local_flag = FAILED;
86 		} else {
87 			fclose(stream);
88 			unlink(tempfile1);
89 		}
90 		if (local_flag == PASSED) {
91 			tst_resm(TPASS, "Test passed in block0.");
92 		} else {
93 			tst_resm(TFAIL, "Test failed in block0.");
94 		}
95 		local_flag = PASSED;
96 
97 	/*--------------------------------------------------------------------*/
98 block1:
99 		if ((fd = open("/dev/tty", O_WRONLY)) >= 0) {
100 			close(fd);
101 			if ((stream = fopen("/dev/tty", "w")) == NULL) {
102 				tst_resm(TFAIL | TERRNO,
103 					 "fopen(/dev/tty) write failed");
104 				local_flag = FAILED;
105 			} else {
106 				fclose(stream);
107 			}
108 		}
109 		if (local_flag == PASSED) {
110 			tst_resm(TPASS, "Test passed in block1.");
111 		} else {
112 			tst_resm(TFAIL, "Test failed in block1.");
113 		}
114 
115 	/*--------------------------------------------------------------------*/
116 	}			/* end for */
117 	tst_rmdir();
118 	tst_exit();
119 }
120