- if ((fd = open(file, O_RDONLY, 0)) < 0)
- perror_msg_and_die("%s", file);
+ switch (code->value) {
+ case MTWEOF:
+ case MTERASE:
+ case MTWSM:
+ case MTSETDRVBUFFER:
+ mode = O_WRONLY;
+ break;
+
+ default:
+ mode = O_RDONLY;
+ break;
+ }
+
+ fd = bb_xopen3(file, mode, 0);
+
+ switch (code->value) {
+ case MTTELL:
+ if (ioctl(fd, MTIOCPOS, &position) < 0)
+ bb_perror_msg_and_die("%s", file);
+ printf ("At block %d.\n", (int) position.mt_blkno);
+ break;