rmt.c (f08566c3cf1af0a470cdefdd90081c45686804dd) | rmt.c (e1b4d8d0746069292d84708b0e11b17a7e1ef5e0) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 84 unchanged lines hidden (view full) --- 93 debug = fopen(*argv, "w"); 94 if (debug == 0) 95 exit(1); 96 (void)setbuf(debug, (char *)0); 97 } 98top: 99 errno = 0; 100 rval = 0; | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 84 unchanged lines hidden (view full) --- 93 debug = fopen(*argv, "w"); 94 if (debug == 0) 95 exit(1); 96 (void)setbuf(debug, (char *)0); 97 } 98top: 99 errno = 0; 100 rval = 0; |
101 if (read(0, &c, 1) != 1) | 101 if (read(STDIN_FILENO, &c, 1) != 1) |
102 exit(0); 103 switch (c) { 104 105 case 'O': 106 if (tape >= 0) 107 (void) close(tape); 108 getstring(device); 109 getstring(mode); --- 26 unchanged lines hidden (view full) --- 136 goto respond; 137 138 case 'W': 139 getstring(count); 140 n = atoi(count); 141 DEBUG1("rmtd: W %s\n", count); 142 record = checkbuf(record, n); 143 for (i = 0; i < n; i += cc) { | 102 exit(0); 103 switch (c) { 104 105 case 'O': 106 if (tape >= 0) 107 (void) close(tape); 108 getstring(device); 109 getstring(mode); --- 26 unchanged lines hidden (view full) --- 136 goto respond; 137 138 case 'W': 139 getstring(count); 140 n = atoi(count); 141 DEBUG1("rmtd: W %s\n", count); 142 record = checkbuf(record, n); 143 for (i = 0; i < n; i += cc) { |
144 cc = read(0, &record[i], n - i); | 144 cc = read(STDIN_FILENO, &record[i], n - i); |
145 if (cc <= 0) { 146 DEBUG("rmtd: premature eof\n"); 147 exit(2); 148 } 149 } 150 rval = write(tape, record, n); 151 if (rval < 0) 152 goto ioerror; 153 goto respond; 154 155 case 'R': 156 getstring(count); 157 DEBUG1("rmtd: R %s\n", count); 158 n = atoi(count); 159 record = checkbuf(record, n); 160 rval = read(tape, record, n); 161 if (rval < 0) 162 goto ioerror; 163 (void)sprintf(resp, "A%d\n", rval); | 145 if (cc <= 0) { 146 DEBUG("rmtd: premature eof\n"); 147 exit(2); 148 } 149 } 150 rval = write(tape, record, n); 151 if (rval < 0) 152 goto ioerror; 153 goto respond; 154 155 case 'R': 156 getstring(count); 157 DEBUG1("rmtd: R %s\n", count); 158 n = atoi(count); 159 record = checkbuf(record, n); 160 rval = read(tape, record, n); 161 if (rval < 0) 162 goto ioerror; 163 (void)sprintf(resp, "A%d\n", rval); |
164 (void)write(1, resp, strlen(resp)); 165 (void)write(1, record, rval); | 164 (void)write(STDOUT_FILENO, resp, strlen(resp)); 165 (void)write(STDOUT_FILENO, record, rval); |
166 goto top; 167 168 case 'I': 169 getstring(op); 170 getstring(count); 171 DEBUG2("rmtd: I %s %s\n", op, count); 172 { struct mtop mtop; 173 mtop.mt_op = atoi(op); --- 8 unchanged lines hidden (view full) --- 182 DEBUG("rmtd: S\n"); 183 { struct mtget mtget; 184 if (ioctl(tape, MTIOCGET, (char *)&mtget) < 0) 185 goto ioerror; 186 rval = sizeof (mtget); 187 if (rval > 24) /* original mtget structure size */ 188 rval = 24; 189 (void)sprintf(resp, "A%d\n", rval); | 166 goto top; 167 168 case 'I': 169 getstring(op); 170 getstring(count); 171 DEBUG2("rmtd: I %s %s\n", op, count); 172 { struct mtop mtop; 173 mtop.mt_op = atoi(op); --- 8 unchanged lines hidden (view full) --- 182 DEBUG("rmtd: S\n"); 183 { struct mtget mtget; 184 if (ioctl(tape, MTIOCGET, (char *)&mtget) < 0) 185 goto ioerror; 186 rval = sizeof (mtget); 187 if (rval > 24) /* original mtget structure size */ 188 rval = 24; 189 (void)sprintf(resp, "A%d\n", rval); |
190 (void)write(1, resp, strlen(resp)); 191 (void)write(1, (char *)&mtget, rval); | 190 (void)write(STDOUT_FILENO, resp, strlen(resp)); 191 (void)write(STDOUT_FILENO, (char *)&mtget, rval); |
192 goto top; 193 } 194 195 case 'V': /* version */ 196 getstring(op); 197 DEBUG1("rmtd: V %s\n", op); 198 rval = 2; 199 goto respond; 200 201 default: 202 DEBUG1("rmtd: garbage command %c\n", c); 203 exit(3); 204 } 205respond: 206 DEBUG1("rmtd: A %d\n", rval); 207 (void)sprintf(resp, "A%d\n", rval); | 192 goto top; 193 } 194 195 case 'V': /* version */ 196 getstring(op); 197 DEBUG1("rmtd: V %s\n", op); 198 rval = 2; 199 goto respond; 200 201 default: 202 DEBUG1("rmtd: garbage command %c\n", c); 203 exit(3); 204 } 205respond: 206 DEBUG1("rmtd: A %d\n", rval); 207 (void)sprintf(resp, "A%d\n", rval); |
208 (void)write(1, resp, strlen(resp)); | 208 (void)write(STDOUT_FILENO, resp, strlen(resp)); |
209 goto top; 210ioerror: 211 error(errno); 212 goto top; 213} 214 215void 216getstring(bp) 217 char *bp; 218{ 219 int i; 220 char *cp = bp; 221 222 for (i = 0; i < SSIZE; i++) { | 209 goto top; 210ioerror: 211 error(errno); 212 goto top; 213} 214 215void 216getstring(bp) 217 char *bp; 218{ 219 int i; 220 char *cp = bp; 221 222 for (i = 0; i < SSIZE; i++) { |
223 if (read(0, cp+i, 1) != 1) | 223 if (read(STDIN_FILENO, cp+i, 1) != 1) |
224 exit(0); 225 if (cp[i] == '\n') 226 break; 227 } 228 cp[i] = '\0'; 229} 230 231char * --- 20 unchanged lines hidden (view full) --- 252 253void 254error(num) 255 int num; 256{ 257 258 DEBUG2("rmtd: E %d (%s)\n", num, strerror(num)); 259 (void)snprintf(resp, sizeof(resp), "E%d\n%s\n", num, strerror(num)); | 224 exit(0); 225 if (cp[i] == '\n') 226 break; 227 } 228 cp[i] = '\0'; 229} 230 231char * --- 20 unchanged lines hidden (view full) --- 252 253void 254error(num) 255 int num; 256{ 257 258 DEBUG2("rmtd: E %d (%s)\n", num, strerror(num)); 259 (void)snprintf(resp, sizeof(resp), "E%d\n%s\n", num, strerror(num)); |
260 (void)write(1, resp, strlen(resp)); | 260 (void)write(STDOUT_FILENO, resp, strlen(resp)); |
261} | 261} |