X-Git-Url: https://git.wh0rd.org/?p=dump.git;a=blobdiff_plain;f=rmt%2Frmt.c;h=863f12651c68bd103a1972fd52a2078a889ead97;hp=1543a7bca05b51da5efed5cff6c735c0d5c2e88f;hb=HEAD;hpb=d1925e0c515fcb4f815d75292566d600fd715ff5 diff --git a/rmt/rmt.c b/rmt/rmt.c index 1543a7b..863f126 100644 --- a/rmt/rmt.c +++ b/rmt/rmt.c @@ -37,7 +37,7 @@ #ifndef lint static const char rcsid[] = - "$Id: rmt.c,v 1.27 2003/10/26 16:05:49 stelian Exp $"; + "$Id: rmt.c,v 1.29 2010/06/11 11:19:18 stelian Exp $"; #endif /* not linux */ /* @@ -204,7 +204,25 @@ top: getstring(pos); DEBUG2("rmtd: L %s %s\n", count, pos); if (!magtape) { /* traditional */ - rval = LSEEK(tape, (OFF_T)atoll(count), atoi(pos)); + switch (atoi(pos)) { + case SEEK_SET: + case SEEK_CUR: + case SEEK_END: + rval = LSEEK(tape, (OFF_T)atoll(count), atoi(pos)); + break; +#ifdef USE_QFA + case LSEEK_GET_TAPEPOS: + rval = LSEEK(tape, (OFF_T)0, SEEK_CUR); + break; + case LSEEK_GO2_TAPEPOS: + rval = LSEEK(tape, (OFF_T)atoll(count), SEEK_SET); + break; +#endif /* USE_QFA */ + default: + errno = EINVAL; + goto ioerror; + break; + } } else { switch (atoi(pos)) { @@ -292,8 +310,10 @@ top: cp = record; #endif (void)sprintf(resp, "A%lld\n", (long long)rval); - (void)write(1, resp, strlen(resp)); - (void)write(1, cp, rval); + if (write(1, resp, strlen(resp)) != strlen(resp)) + goto ioerror; + if (write(1, cp, rval) != rval) + goto ioerror; block += n >> 10; goto top; @@ -457,13 +477,17 @@ top: mtget.mt_fileno = swaplong(mtget.mt_fileno); mtget.mt_blkno = swaplong(mtget.mt_blkno); (void)sprintf(resp, "A%lld\n", (long long)rval); - (void)write(1, resp, strlen(resp)); - (void)write(1, (char *)&mtget, sizeof (mtget)); + if (write(1, resp, strlen(resp)) != strlen(resp)) + goto ioerror; + if (write(1, (char *)&mtget, sizeof (mtget)) != sizeof(mtget)) + goto ioerror; } else { rval = sizeof (mtget); (void)sprintf(resp, "A%lld\n", (long long)rval); - (void)write(1, resp, strlen(resp)); - (void)write(1, (char *)&mtget, sizeof (mtget)); + if (write(1, resp, strlen(resp)) != strlen(resp)) + goto ioerror; + if (write(1, (char *)&mtget, sizeof (mtget)) != sizeof(mtget)) + goto ioerror; } goto top; } @@ -528,7 +552,8 @@ top: respond: DEBUG1("rmtd: A %lld\n", (long long)rval); (void)sprintf(resp, "A%lld\n", (long long)rval); - (void)write(1, resp, strlen(resp)); + if (write(1, resp, strlen(resp)) != strlen(resp)) + goto ioerror; goto top; ioerror: error(errno); @@ -575,7 +600,8 @@ error(int num) DEBUG2("rmtd: E %d (%s)\n", num, strerror(num)); (void)snprintf(resp, sizeof(resp), "E%d\n%s\n", num, strerror(num)); - (void)write(1, resp, strlen(resp)); + if (write(1, resp, strlen(resp)) != strlen(resp)) + DEBUG("rmtd: write error\n"); } static unsigned long