- if (tape < 0)
- goto ioerror;
- goto respond;
-
- case 'C':
- DEBUG("rmtd: C\n");
- getstring(device); /* discard */
- if (close(tape) < 0)
- goto ioerror;
- tape = -1;
- goto respond;
-
- case 'L':
- getstring(count); getstring(pos);
- DEBUG2("rmtd: L %s %s\n", count, pos);
- rval = lseek(tape, (long) atoi(count), atoi(pos));
- if (rval < 0)
- goto ioerror;
- goto respond;
-
- case 'W':
- getstring(count);
- n = atoi(count);
- DEBUG1("rmtd: W %s\n", count);
- record = checkbuf(record, n);
- for (i = 0; i < n; i += cc) {
- cc = read(0, &record[i], n - i);
- if (cc <= 0) {
- DEBUG("rmtd: premature eof\n");
- exit(2);
- }
- }
- rval = write(tape, record, n);
- if (rval < 0)
- goto ioerror;
- goto respond;
-
- case 'R':
- getstring(count);
- DEBUG1("rmtd: R %s\n", count);
- n = atoi(count);
- record = checkbuf(record, n);
- rval = read(tape, record, n);
- if (rval < 0)
- goto ioerror;
- (void) sprintf(resp, "A%d\n", rval);
- (void) write(1, resp, strlen(resp));
- (void) write(1, record, rval);
- goto top;
-
- case 'I':
- getstring(op); getstring(count);
- DEBUG2("rmtd: I %s %s\n", op, count);
+ if (tape < 0)
+ goto ioerror;
+ goto respond;
+ }
+
+ case 'C':
+ {
+ char device_string[STRING_SIZE];
+
+ get_string (device_string); /* discard */
+ DEBUG ("rmtd: C\n");
+
+ if (close (tape) < 0)
+ goto ioerror;
+ tape = -1;
+ goto respond;
+ }
+
+ case 'L':
+ {
+ char count_string[STRING_SIZE];
+ char position_string[STRING_SIZE];
+
+ get_string (count_string);
+ get_string (position_string);
+ DEBUG2 ("rmtd: L %s %s\n", count_string, position_string);
+
+ status
+ = lseek (tape, (off_t) atol (count_string), atoi (position_string));
+ if (status < 0)
+ goto ioerror;
+ goto respond;
+ }
+
+ case 'W':
+ {
+ char count_string[STRING_SIZE];
+ int size;
+ int counter;
+
+ get_string (count_string);
+ size = atoi (count_string);
+ DEBUG1 ("rmtd: W %s\n", count_string);
+
+ prepare_record_buffer (size);
+ for (counter = 0; counter < size; counter += status)
+ {
+ status = read (0, &record_buffer[counter], size - counter);
+ if (status <= 0)
+ {
+ DEBUG (_("rmtd: Premature eof\n"));
+
+ report_error_message (N_("Premature end of file"));
+ exit (EXIT_FAILURE); /* exit status used to be 2 */
+ }
+ }
+ status = write (tape, record_buffer, size);
+ if (status < 0)
+ goto ioerror;
+ goto respond;
+ }
+
+ case 'R':
+ {
+ char count_string[STRING_SIZE];
+ int size;
+
+ get_string (count_string);
+ DEBUG1 ("rmtd: R %s\n", count_string);
+
+ size = atoi (count_string);
+ prepare_record_buffer (size);
+ status = read (tape, record_buffer, size);
+ if (status < 0)
+ goto ioerror;
+ sprintf (reply_buffer, "A%d\n", status);
+ write (1, reply_buffer, strlen (reply_buffer));
+ write (1, record_buffer, status);
+ goto top;
+ }
+
+ case 'I':
+ {
+ char operation_string[STRING_SIZE];
+ char count_string[STRING_SIZE];
+
+ get_string (operation_string);
+ get_string (count_string);
+ DEBUG2 ("rmtd: I %s %s\n", operation_string, count_string);
+