1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker *
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) International Business Machines Corp., 2002
4*49cdfc7eSAndroid Build Coastguard Worker *
5*49cdfc7eSAndroid Build Coastguard Worker * This program is free software; you can redistribute it and/or modify
6*49cdfc7eSAndroid Build Coastguard Worker * it under the terms of the GNU General Public License as published by
7*49cdfc7eSAndroid Build Coastguard Worker * the Free Software Foundation; either version 2 of the License, or
8*49cdfc7eSAndroid Build Coastguard Worker * (at your option) any later version.
9*49cdfc7eSAndroid Build Coastguard Worker *
10*49cdfc7eSAndroid Build Coastguard Worker * This program is distributed in the hope that it will be useful,
11*49cdfc7eSAndroid Build Coastguard Worker * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*49cdfc7eSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13*49cdfc7eSAndroid Build Coastguard Worker * the GNU General Public License for more details.
14*49cdfc7eSAndroid Build Coastguard Worker *
15*49cdfc7eSAndroid Build Coastguard Worker * You should have received a copy of the GNU General Public License
16*49cdfc7eSAndroid Build Coastguard Worker * along with this program; if not, write to the Free Software
17*49cdfc7eSAndroid Build Coastguard Worker * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*49cdfc7eSAndroid Build Coastguard Worker */
19*49cdfc7eSAndroid Build Coastguard Worker /* ported from SPIE section2/filesuite/stream2.c, by Airong Zhang */
20*49cdfc7eSAndroid Build Coastguard Worker
21*49cdfc7eSAndroid Build Coastguard Worker /*======================================================================
22*49cdfc7eSAndroid Build Coastguard Worker =================== TESTPLAN SEGMENT ===================
23*49cdfc7eSAndroid Build Coastguard Worker >KEYS: < fseek() mknod() fopen()
24*49cdfc7eSAndroid Build Coastguard Worker >WHAT: < 1)
25*49cdfc7eSAndroid Build Coastguard Worker >HOW: < 1)
26*49cdfc7eSAndroid Build Coastguard Worker >BUGS: <
27*49cdfc7eSAndroid Build Coastguard Worker ======================================================================*/
28*49cdfc7eSAndroid Build Coastguard Worker
29*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
30*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
31*49cdfc7eSAndroid Build Coastguard Worker #include <fcntl.h>
32*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
33*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
34*49cdfc7eSAndroid Build Coastguard Worker #include <sys/stat.h>
35*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
36*49cdfc7eSAndroid Build Coastguard Worker
37*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "stream02";
38*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = 1;
39*49cdfc7eSAndroid Build Coastguard Worker int local_flag;
40*49cdfc7eSAndroid Build Coastguard Worker
41*49cdfc7eSAndroid Build Coastguard Worker #define PASSED 1
42*49cdfc7eSAndroid Build Coastguard Worker #define FAILED 0
43*49cdfc7eSAndroid Build Coastguard Worker
44*49cdfc7eSAndroid Build Coastguard Worker char progname[] = "stream02()";
45*49cdfc7eSAndroid Build Coastguard Worker char tempfile1[40] = "";
46*49cdfc7eSAndroid Build Coastguard Worker
47*49cdfc7eSAndroid Build Coastguard Worker /* XXX: add cleanup + setup. */
48*49cdfc7eSAndroid Build Coastguard Worker
49*49cdfc7eSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*/
main(int ac,char * av[])50*49cdfc7eSAndroid Build Coastguard Worker int main(int ac, char *av[])
51*49cdfc7eSAndroid Build Coastguard Worker {
52*49cdfc7eSAndroid Build Coastguard Worker FILE *stream;
53*49cdfc7eSAndroid Build Coastguard Worker int fd;
54*49cdfc7eSAndroid Build Coastguard Worker int lc;
55*49cdfc7eSAndroid Build Coastguard Worker
56*49cdfc7eSAndroid Build Coastguard Worker /*
57*49cdfc7eSAndroid Build Coastguard Worker * parse standard options
58*49cdfc7eSAndroid Build Coastguard Worker */
59*49cdfc7eSAndroid Build Coastguard Worker tst_parse_opts(ac, av, NULL, NULL);
60*49cdfc7eSAndroid Build Coastguard Worker
61*49cdfc7eSAndroid Build Coastguard Worker local_flag = PASSED;
62*49cdfc7eSAndroid Build Coastguard Worker tst_tmpdir();
63*49cdfc7eSAndroid Build Coastguard Worker
64*49cdfc7eSAndroid Build Coastguard Worker for (lc = 0; TEST_LOOPING(lc); lc++) {
65*49cdfc7eSAndroid Build Coastguard Worker
66*49cdfc7eSAndroid Build Coastguard Worker sprintf(tempfile1, "stream1.%d", getpid());
67*49cdfc7eSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*/
68*49cdfc7eSAndroid Build Coastguard Worker //block0:
69*49cdfc7eSAndroid Build Coastguard Worker if (mknod(tempfile1, (S_IFIFO | 0666), 0) != 0) {
70*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "mknod failed in block0: %s",
71*49cdfc7eSAndroid Build Coastguard Worker strerror(errno));
72*49cdfc7eSAndroid Build Coastguard Worker local_flag = FAILED;
73*49cdfc7eSAndroid Build Coastguard Worker goto block1;
74*49cdfc7eSAndroid Build Coastguard Worker }
75*49cdfc7eSAndroid Build Coastguard Worker if ((stream = fopen(tempfile1, "w+")) == NULL) {
76*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "fopen(%s) w+ failed for pipe file: %s",
77*49cdfc7eSAndroid Build Coastguard Worker tempfile1, strerror(errno));
78*49cdfc7eSAndroid Build Coastguard Worker local_flag = FAILED;
79*49cdfc7eSAndroid Build Coastguard Worker } else {
80*49cdfc7eSAndroid Build Coastguard Worker fclose(stream);
81*49cdfc7eSAndroid Build Coastguard Worker }
82*49cdfc7eSAndroid Build Coastguard Worker if ((stream = fopen(tempfile1, "a+")) == NULL) {
83*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "fopen(%s) a+ failed: %s", tempfile1,
84*49cdfc7eSAndroid Build Coastguard Worker strerror(errno));
85*49cdfc7eSAndroid Build Coastguard Worker local_flag = FAILED;
86*49cdfc7eSAndroid Build Coastguard Worker } else {
87*49cdfc7eSAndroid Build Coastguard Worker fclose(stream);
88*49cdfc7eSAndroid Build Coastguard Worker unlink(tempfile1);
89*49cdfc7eSAndroid Build Coastguard Worker }
90*49cdfc7eSAndroid Build Coastguard Worker if (local_flag == PASSED) {
91*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TPASS, "Test passed in block0.");
92*49cdfc7eSAndroid Build Coastguard Worker } else {
93*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "Test failed in block0.");
94*49cdfc7eSAndroid Build Coastguard Worker }
95*49cdfc7eSAndroid Build Coastguard Worker local_flag = PASSED;
96*49cdfc7eSAndroid Build Coastguard Worker
97*49cdfc7eSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*/
98*49cdfc7eSAndroid Build Coastguard Worker block1:
99*49cdfc7eSAndroid Build Coastguard Worker if ((fd = open("/dev/tty", O_WRONLY)) >= 0) {
100*49cdfc7eSAndroid Build Coastguard Worker close(fd);
101*49cdfc7eSAndroid Build Coastguard Worker if ((stream = fopen("/dev/tty", "w")) == NULL) {
102*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL | TERRNO,
103*49cdfc7eSAndroid Build Coastguard Worker "fopen(/dev/tty) write failed");
104*49cdfc7eSAndroid Build Coastguard Worker local_flag = FAILED;
105*49cdfc7eSAndroid Build Coastguard Worker } else {
106*49cdfc7eSAndroid Build Coastguard Worker fclose(stream);
107*49cdfc7eSAndroid Build Coastguard Worker }
108*49cdfc7eSAndroid Build Coastguard Worker }
109*49cdfc7eSAndroid Build Coastguard Worker if (local_flag == PASSED) {
110*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TPASS, "Test passed in block1.");
111*49cdfc7eSAndroid Build Coastguard Worker } else {
112*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "Test failed in block1.");
113*49cdfc7eSAndroid Build Coastguard Worker }
114*49cdfc7eSAndroid Build Coastguard Worker
115*49cdfc7eSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*/
116*49cdfc7eSAndroid Build Coastguard Worker } /* end for */
117*49cdfc7eSAndroid Build Coastguard Worker tst_rmdir();
118*49cdfc7eSAndroid Build Coastguard Worker tst_exit();
119*49cdfc7eSAndroid Build Coastguard Worker }
120