Add errno.h
[oweals/busybox.git] / mt.c
diff --git a/mt.c b/mt.c
index 9791b64b204b796cce108027165a520b1a2cfd09..70d03cca40177f3f02d9ca29d26faab33423f8f0 100644 (file)
--- a/mt.c
+++ b/mt.c
@@ -1,11 +1,9 @@
 /* vi: set sw=4 ts=4: */
-#include "internal.h"
+#include "busybox.h"
 #include <stdio.h>
 #include <sys/mtio.h>
 #include <sys/fcntl.h>
 
-static const char mt_usage[] = "mt [-f device] opcode value\n";
-
 struct mt_opcodes {
        char *name;
        short value;
@@ -56,6 +54,10 @@ extern int mt_main(int argc, char **argv)
        const struct mt_opcodes *code = opcodes;
        struct mtop op;
        int fd;
+       
+       if (argc < 2) {
+               usage(mt_usage);
+       }
 
        if (strcmp(argv[1], "-f") == 0) {
                if (argc < 4) {
@@ -73,8 +75,8 @@ extern int mt_main(int argc, char **argv)
        }
 
        if (code->name == 0) {
-               fprintf(stderr, "mt: unrecognized opcode %s.\n", argv[1]);
-               return (FALSE);
+               error_msg("unrecognized opcode %s.\n", argv[1]);
+               return EXIT_FAILURE;
        }
 
        op.mt_op = code->value;
@@ -83,15 +85,11 @@ extern int mt_main(int argc, char **argv)
        else
                op.mt_count = 1;                /* One, not zero, right? */
 
-       if ((fd = open(file, O_RDONLY, 0)) < 0) {
-               perror(file);
-               return (FALSE);
-       }
+       if ((fd = open(file, O_RDONLY, 0)) < 0)
+               perror_msg_and_die("%s", file);
 
-       if (ioctl(fd, MTIOCTOP, &op) != 0) {
-               perror(file);
-               return (FALSE);
-       }
+       if (ioctl(fd, MTIOCTOP, &op) != 0)
+               perror_msg_and_die("%s", file);
 
-       return (TRUE);
+       return EXIT_SUCCESS;
 }