robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 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., 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> |
robbiew | a70576c | 2003-03-04 18:33:41 +0000 | [diff] [blame] | 30 | #include <errno.h> |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 31 | #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 | |
| 38 | char *TCID = "stream02"; |
| 39 | int TST_TOTAL = 1; |
| 40 | extern int Tst_count; |
| 41 | int local_flag; |
| 42 | |
| 43 | #define PASSED 1 |
| 44 | #define FAILED 0 |
| 45 | |
| 46 | |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 47 | char progname[] = "stream02()" ; |
| 48 | char tempfile1[40]=""; |
| 49 | |
| 50 | /*--------------------------------------------------------------------*/ |
| 51 | int 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: |
robbiew | 631dd65 | 2003-06-10 15:00:41 +0000 | [diff] [blame^] | 75 | if(mknod(tempfile1, (S_IFIFO|0666), 0) != 0) { |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 76 | 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; |
robbiew | 631dd65 | 2003-06-10 15:00:41 +0000 | [diff] [blame^] | 83 | } else { |
| 84 | fclose(stream); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 85 | } |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 86 | if((stream=fopen(tempfile1,"a+")) == NULL) { |
| 87 | tst_resm(TFAIL,"\tfopen a+ failed\n"); |
| 88 | local_flag = FAILED; |
robbiew | 631dd65 | 2003-06-10 15:00:41 +0000 | [diff] [blame^] | 89 | } else { |
| 90 | fclose(stream); |
| 91 | unlink(tempfile1); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 92 | } |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 93 | 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; |
robbiew | 631dd65 | 2003-06-10 15:00:41 +0000 | [diff] [blame^] | 108 | } else { |
| 109 | fclose(stream); |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 110 | } |
robbiew | c844563 | 2003-01-06 21:35:55 +0000 | [diff] [blame] | 111 | } |
| 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 | } |