X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Frmt.c;h=557b6d4224c8220257e8ee559f41353f5ba23323;hb=2016526b1a880b8375d9c77299d3339122fccc0e;hp=bf2e0a128640a6fd5850104f331a85ad47c5ff22;hpb=6290150c47daea1d034f2293756b623169ad1b9b;p=chaz%2Ftar diff --git a/src/rmt.c b/src/rmt.c index bf2e0a1..557b6d4 100644 --- a/src/rmt.c +++ b/src/rmt.c @@ -30,6 +30,7 @@ MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include "system.h" +#include "safe-read.h" #include @@ -128,7 +129,7 @@ get_string (char *string) for (counter = 0; counter < STRING_SIZE; counter++) { - if (full_read (STDIN_FILENO, string + counter, 1) != 1) + if (safe_read (STDIN_FILENO, string + counter, 1) != 1) exit (EXIT_SUCCESS); if (string[counter] == '\n') @@ -210,7 +211,7 @@ main (int argc, char *const *argv) top: errno = 0; /* FIXME: errno should be read-only */ status = 0; - if (full_read (STDIN_FILENO, &command, 1) != 1) + if (safe_read (STDIN_FILENO, &command, 1) != 1) exit (EXIT_SUCCESS); switch (command) @@ -254,6 +255,7 @@ top: char position_string[STRING_SIZE]; off_t count = 0; int negative; + int whence; char *p; get_string (count_string); @@ -288,7 +290,16 @@ top: } } - count = lseek (tape, count, atoi (position_string)); + switch (atoi (position_string)) + { + case 0: whence = SEEK_SET; break; + case 1: whence = SEEK_CUR; break; + case 2: whence = SEEK_END; break; + default: + report_error_message (N_("Seek direction out of range")); + exit (EXIT_FAILURE); + } + count = lseek (tape, count, whence); if (count < 0) goto ioerror; @@ -320,8 +331,8 @@ top: prepare_record_buffer (size); for (counter = 0; counter < size; counter += status) { - status = full_read (STDIN_FILENO, &record_buffer[counter], - size - counter); + status = safe_read (STDIN_FILENO, &record_buffer[counter], + size - counter); if (status <= 0) { DEBUG (_("rmtd: Premature eof\n")); @@ -346,7 +357,7 @@ top: size = atol (count_string); prepare_record_buffer (size); - status = full_read (tape, record_buffer, size); + status = safe_read (tape, record_buffer, size); if (status < 0) goto ioerror; sprintf (reply_buffer, "A%ld\n", status);