ignore -t in -bd mode
[unix-history] / usr / src / usr.sbin / rmt / rmt.c
index 73adc31..cedad28 100644 (file)
@@ -1,61 +1,55 @@
 /*
 /*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1983, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1983 Regents of the University of California.\n\
- All rights reserved.\n";
+static char copyright[] =
+"@(#) Copyright (c) 1983, 1993\n\
      The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)rmt.c      5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)rmt.c      8.1 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
  * rmt
  */
 #endif /* not lint */
 
 /*
  * rmt
  */
-#include <stdio.h>
-#include <sgtty.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/mtio.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/mtio.h>
 #include <errno.h>
+#include <fcntl.h>
+#include <sgtty.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 
 int    tape = -1;
 
 char   *record;
 int    maxrecsize = -1;
 
 int    tape = -1;
 
 char   *record;
 int    maxrecsize = -1;
-char   *checkbuf();
 
 #define        SSIZE   64
 char   device[SSIZE];
 char   count[SSIZE], mode[SSIZE], pos[SSIZE], op[SSIZE];
 
 
 #define        SSIZE   64
 char   device[SSIZE];
 char   count[SSIZE], mode[SSIZE], pos[SSIZE], op[SSIZE];
 
-extern errno;
-char   *sys_errlist[];
 char   resp[BUFSIZ];
 
 char   resp[BUFSIZ];
 
-long   lseek();
-
 FILE   *debug;
 #define        DEBUG(f)        if (debug) fprintf(debug, f)
 #define        DEBUG1(f,a)     if (debug) fprintf(debug, f, a)
 #define        DEBUG2(f,a1,a2) if (debug) fprintf(debug, f, a1, a2)
 
 FILE   *debug;
 #define        DEBUG(f)        if (debug) fprintf(debug, f)
 #define        DEBUG1(f,a)     if (debug) fprintf(debug, f, a)
 #define        DEBUG2(f,a1,a2) if (debug) fprintf(debug, f, a1, a2)
 
+char   *checkbuf __P((char *, int));
+void    error __P((int));
+void    getstring __P((char *));
+
+int
 main(argc, argv)
        int argc;
        char **argv;
 main(argc, argv)
        int argc;
        char **argv;
@@ -69,7 +63,7 @@ main(argc, argv)
                debug = fopen(*argv, "w");
                if (debug == 0)
                        exit(1);
                debug = fopen(*argv, "w");
                if (debug == 0)
                        exit(1);
-               (void) setbuf(debug, (char *)0);
+               (void)setbuf(debug, (char *)0);
        }
 top:
        errno = 0;
        }
 top:
        errno = 0;
@@ -81,7 +75,8 @@ top:
        case 'O':
                if (tape >= 0)
                        (void) close(tape);
        case 'O':
                if (tape >= 0)
                        (void) close(tape);
-               getstring(device); getstring(mode);
+               getstring(device);
+               getstring(mode);
                DEBUG2("rmtd: O %s %s\n", device, mode);
                tape = open(device, atoi(mode));
                if (tape < 0)
                DEBUG2("rmtd: O %s %s\n", device, mode);
                tape = open(device, atoi(mode));
                if (tape < 0)
@@ -97,9 +92,10 @@ top:
                goto respond;
 
        case 'L':
                goto respond;
 
        case 'L':
-               getstring(count); getstring(pos);
+               getstring(count);
+               getstring(pos);
                DEBUG2("rmtd: L %s %s\n", count, pos);
                DEBUG2("rmtd: L %s %s\n", count, pos);
-               rval = lseek(tape, (long) atoi(count), atoi(pos));
+               rval = lseek(tape, (off_t)atol(count), atoi(pos));
                if (rval < 0)
                        goto ioerror;
                goto respond;
                if (rval < 0)
                        goto ioerror;
                goto respond;
@@ -129,13 +125,14 @@ top:
                rval = read(tape, record, n);
                if (rval < 0)
                        goto ioerror;
                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);
+               (void)sprintf(resp, "A%d\n", rval);
+               (void)write(1, resp, strlen(resp));
+               (void)write(1, record, rval);
                goto top;
 
        case 'I':
                goto top;
 
        case 'I':
-               getstring(op); getstring(count);
+               getstring(op);
+               getstring(count);
                DEBUG2("rmtd: I %s %s\n", op, count);
                { struct mtop mtop;
                  mtop.mt_op = atoi(op);
                DEBUG2("rmtd: I %s %s\n", op, count);
                { struct mtop mtop;
                  mtop.mt_op = atoi(op);
@@ -152,9 +149,9 @@ top:
                  if (ioctl(tape, MTIOCGET, (char *)&mtget) < 0)
                        goto ioerror;
                  rval = sizeof (mtget);
                  if (ioctl(tape, MTIOCGET, (char *)&mtget) < 0)
                        goto ioerror;
                  rval = sizeof (mtget);
-                 (void) sprintf(resp, "A%d\n", rval);
-                 (void) write(1, resp, strlen(resp));
-                 (void) write(1, (char *)&mtget, sizeof (mtget));
+                 (void)sprintf(resp, "A%d\n", rval);
+                 (void)write(1, resp, strlen(resp));
+                 (void)write(1, (char *)&mtget, sizeof (mtget));
                  goto top;
                }
 
                  goto top;
                }
 
@@ -164,14 +161,15 @@ top:
        }
 respond:
        DEBUG1("rmtd: A %d\n", rval);
        }
 respond:
        DEBUG1("rmtd: A %d\n", rval);
-       (void) sprintf(resp, "A%d\n", rval);
-       (void) write(1, resp, strlen(resp));
+       (void)sprintf(resp, "A%d\n", rval);
+       (void)write(1, resp, strlen(resp));
        goto top;
 ioerror:
        error(errno);
        goto top;
 }
 
        goto top;
 ioerror:
        error(errno);
        goto top;
 }
 
+void
 getstring(bp)
        char *bp;
 {
 getstring(bp)
        char *bp;
 {
@@ -192,7 +190,6 @@ checkbuf(record, size)
        char *record;
        int size;
 {
        char *record;
        int size;
 {
-       extern char *malloc();
 
        if (size <= maxrecsize)
                return (record);
 
        if (size <= maxrecsize)
                return (record);
@@ -210,11 +207,12 @@ checkbuf(record, size)
        return (record);
 }
 
        return (record);
 }
 
+void
 error(num)
        int num;
 {
 
 error(num)
        int num;
 {
 
-       DEBUG2("rmtd: E %d (%s)\n", num, sys_errlist[num]);
-       (void) sprintf(resp, "E%d\n%s\n", num, sys_errlist[num]);
-       (void) write(1, resp, strlen (resp));
+       DEBUG2("rmtd: E %d (%s)\n", num, strerror(num));
+       (void)sprintf(resp, "E%d\n%s\n", num, strerror(num));
+       (void)write(1, resp, strlen(resp));
 }
 }