blob: fd03132a335db0ba5177e3cea8388cd1b13b27e4 [file] [log] [blame]
robbiewc8445632003-01-06 21:35:55 +00001/*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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>
robbiewa70576c2003-03-04 18:33:41 +000030#include <errno.h>
robbiewc8445632003-01-06 21:35:55 +000031#include <fcntl.h>
32#include <unistd.h>
33#include <sys/types.h>
34#include <sys/stat.h>
35#include "test.h"
36#include "usctest.h"
37
38char *TCID = "stream02";
39int TST_TOTAL = 1;
40extern int Tst_count;
41int local_flag;
42
43#define PASSED 1
44#define FAILED 0
45
46
robbiewc8445632003-01-06 21:35:55 +000047char progname[] = "stream02()" ;
48char tempfile1[40]="";
49
50/*--------------------------------------------------------------------*/
51int main(int ac, char *av[])
52{
53 FILE *stream;
54 int fd;
55 int lc; /* loop counter */
56 char *msg; /* message returned from parse_opts */
57
58 /*
59 * parse standard options
60 */
61 if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){
62 tst_resm(TBROK, "OPTION PARSING ERROR - %s", msg);
63 tst_exit();
64 /*NOTREACHED*/
65 }
66
67 local_flag = PASSED;
68 tst_tmpdir();
69
70 for (lc = 0; TEST_LOOPING(lc); lc++) {
71
72 sprintf(tempfile1, "stream1.%d", getpid());
73 /*--------------------------------------------------------------------*/
74 //block0:
robbiew631dd652003-06-10 15:00:41 +000075 if(mknod(tempfile1, (S_IFIFO|0666), 0) != 0) {
robbiewc8445632003-01-06 21:35:55 +000076 tst_resm(TFAIL,"\tmknod failed in block0\n");
77 local_flag = FAILED;
78 goto block1;
79 }
80 if((stream=fopen(tempfile1,"w+")) == NULL) {
81 tst_resm(TFAIL,"\tfopen w+ failed for pipe file\n");
82 local_flag = FAILED;
robbiew631dd652003-06-10 15:00:41 +000083 } else {
84 fclose(stream);
robbiewc8445632003-01-06 21:35:55 +000085 }
robbiewc8445632003-01-06 21:35:55 +000086 if((stream=fopen(tempfile1,"a+")) == NULL) {
87 tst_resm(TFAIL,"\tfopen a+ failed\n");
88 local_flag = FAILED;
robbiew631dd652003-06-10 15:00:41 +000089 } else {
90 fclose(stream);
91 unlink(tempfile1);
robbiewc8445632003-01-06 21:35:55 +000092 }
robbiewc8445632003-01-06 21:35:55 +000093 if (local_flag == PASSED) {
94 tst_resm(TPASS, "Test passed in block0.\n");
95 } else {
96 tst_resm(TFAIL, "Test failed in block0.\n");
97 }
98 local_flag = PASSED;
99
100 /*--------------------------------------------------------------------*/
101 block1 :
102 if(( fd = open("/dev/tty",O_WRONLY)) >= 0 )
103 {
104 close(fd);
105 if(( stream = fopen("/dev/tty","w"))==NULL) {
106 tst_resm(TFAIL,"\tfopen write failed for /dev/tty\n");
107 local_flag = FAILED;
robbiew631dd652003-06-10 15:00:41 +0000108 } else {
109 fclose(stream);
robbiewc8445632003-01-06 21:35:55 +0000110 }
robbiewc8445632003-01-06 21:35:55 +0000111 }
112 if (local_flag == PASSED) {
113 tst_resm(TPASS, "Test passed in block1.\n");
114 } else {
115 tst_resm(TFAIL, "Test failed in block1.\n");
116 }
117
118 /*--------------------------------------------------------------------*/
119 } /* end for */
120 tst_rmdir();
121 tst_exit();
122 return(0);
123}