blob: fb65b5926f514b87ddaeb9dd43f3891bcf5c851b [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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
robbiewc8445632003-01-06 21:35:55 +000018 */
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)
subrata_modak4bb656a2009-02-26 12:02:09 +000026>BUGS: <
robbiewc8445632003-01-06 21:35:55 +000027======================================================================*/
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"
robbiewc8445632003-01-06 21:35:55 +000036
37char *TCID = "stream02";
38int TST_TOTAL = 1;
Wanlong Gao354ebb42012-12-07 10:10:04 +080039int local_flag;
robbiewc8445632003-01-06 21:35:55 +000040
41#define PASSED 1
42#define FAILED 0
43
Wanlong Gao354ebb42012-12-07 10:10:04 +080044char progname[] = "stream02()";
45char tempfile1[40] = "";
robbiewc8445632003-01-06 21:35:55 +000046
Garrett Cooper53740502010-12-16 00:04:01 -080047/* XXX: add cleanup + setup. */
48
robbiewc8445632003-01-06 21:35:55 +000049/*--------------------------------------------------------------------*/
50int main(int ac, char *av[])
51{
52 FILE *stream;
53 int fd;
Cyril Hrubis89af32a2012-10-24 16:39:11 +020054 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020055 const char *msg;
robbiewc8445632003-01-06 21:35:55 +000056
Wanlong Gao354ebb42012-12-07 10:10:04 +080057 /*
58 * parse standard options
59 */
60 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper53740502010-12-16 00:04:01 -080061 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiewc8445632003-01-06 21:35:55 +000062
Wanlong Gao354ebb42012-12-07 10:10:04 +080063 local_flag = PASSED;
robbiewc8445632003-01-06 21:35:55 +000064 tst_tmpdir();
65
66 for (lc = 0; TEST_LOOPING(lc); lc++) {
67
68 sprintf(tempfile1, "stream1.%d", getpid());
69 /*--------------------------------------------------------------------*/
Wanlong Gao354ebb42012-12-07 10:10:04 +080070 //block0:
71 if (mknod(tempfile1, (S_IFIFO | 0666), 0) != 0) {
72 tst_resm(TFAIL, "mknod failed in block0: %s",
73 strerror(errno));
robbiewc8445632003-01-06 21:35:55 +000074 local_flag = FAILED;
75 goto block1;
76 }
Wanlong Gao354ebb42012-12-07 10:10:04 +080077 if ((stream = fopen(tempfile1, "w+")) == NULL) {
78 tst_resm(TFAIL, "fopen(%s) w+ failed for pipe file: %s",
79 tempfile1, strerror(errno));
robbiewc8445632003-01-06 21:35:55 +000080 local_flag = FAILED;
robbiew631dd652003-06-10 15:00:41 +000081 } else {
82 fclose(stream);
robbiewc8445632003-01-06 21:35:55 +000083 }
Wanlong Gao354ebb42012-12-07 10:10:04 +080084 if ((stream = fopen(tempfile1, "a+")) == NULL) {
85 tst_resm(TFAIL, "fopen(%s) a+ failed: %s", tempfile1,
86 strerror(errno));
robbiewc8445632003-01-06 21:35:55 +000087 local_flag = FAILED;
robbiew631dd652003-06-10 15:00:41 +000088 } else {
89 fclose(stream);
90 unlink(tempfile1);
robbiewc8445632003-01-06 21:35:55 +000091 }
robbiewc8445632003-01-06 21:35:55 +000092 if (local_flag == PASSED) {
Wanlong Gao354ebb42012-12-07 10:10:04 +080093 tst_resm(TPASS, "Test passed in block0.");
robbiewc8445632003-01-06 21:35:55 +000094 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +080095 tst_resm(TFAIL, "Test failed in block0.");
96 }
robbiewc8445632003-01-06 21:35:55 +000097 local_flag = PASSED;
98
99 /*--------------------------------------------------------------------*/
Wanlong Gao354ebb42012-12-07 10:10:04 +0800100block1:
101 if ((fd = open("/dev/tty", O_WRONLY)) >= 0) {
robbiewc8445632003-01-06 21:35:55 +0000102 close(fd);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800103 if ((stream = fopen("/dev/tty", "w")) == NULL) {
104 tst_resm(TFAIL | TERRNO,
105 "fopen(/dev/tty) write failed");
robbiewc8445632003-01-06 21:35:55 +0000106 local_flag = FAILED;
robbiew631dd652003-06-10 15:00:41 +0000107 } else {
108 fclose(stream);
robbiewc8445632003-01-06 21:35:55 +0000109 }
robbiewc8445632003-01-06 21:35:55 +0000110 }
111 if (local_flag == PASSED) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800112 tst_resm(TPASS, "Test passed in block1.");
robbiewc8445632003-01-06 21:35:55 +0000113 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800114 tst_resm(TFAIL, "Test failed in block1.");
115 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800116
robbiewc8445632003-01-06 21:35:55 +0000117 /*--------------------------------------------------------------------*/
Wanlong Gao354ebb42012-12-07 10:10:04 +0800118 } /* end for */
robbiewc8445632003-01-06 21:35:55 +0000119 tst_rmdir();
120 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700121}