]> Dogcows Code - chaz/tar/blobdiff - src/rtapelib.c
(decode_options): Set newer_time_option to TYPE_MINIMUM, so that
[chaz/tar] / src / rtapelib.c
index 4e04c515d9be2c1bab95f594d27455df10a41d20..6bbcbd9e1f4944cfd83d3721a14425de2882fa19 100644 (file)
    Originally written by Jeff Lee, modified some by Arnold Robbins.  Redone
    as a library that can replace open, read, write, etc., by Fred Fish, with
    some additional work by Arnold Robbins.  Modified to make all rmt* calls
-   into macros for speed by Jay Fenlason.  Use -DHAVE_NETDB_H for rexec
+   into macros for speed by Jay Fenlason.  Use -DWITH_REXEC for rexec
    code, courtesy of Dan Kegel.  */
 
 #include "system.h"
 
+#include "basename.h"
+#include "safe-read.h"
+
 /* Try hard to get EOPNOTSUPP defined.  486/ISC has it in net/errno.h,
    3B2/SVR3 has it in sys/inet.h.  Otherwise, like on MSDOS, use EINVAL.  */
 
@@ -119,7 +122,7 @@ do_command (int handle, const char *buffer)
 
   pipe_handler = signal (SIGPIPE, SIG_IGN);
   length = strlen (buffer);
-  if (write (WRITE_SIDE (handle), buffer, length) == length)
+  if (full_write (WRITE_SIDE (handle), buffer, length) == length)
     {
       signal (SIGPIPE, pipe_handler);
       return 0;
@@ -144,7 +147,7 @@ get_status_string (int handle, char *command_buffer)
        counter < COMMAND_BUFFER_SIZE;
        counter++, cursor++)
     {
-      if (read (READ_SIDE (handle), cursor, 1) != 1)
+      if (safe_read (READ_SIDE (handle), cursor, 1) != 1)
        {
          _rmt_shutdown (handle, EIO);
          return 0;
@@ -180,7 +183,7 @@ get_status_string (int handle, char *command_buffer)
       {
        char character;
 
-       while (read (READ_SIDE (handle), &character, 1) == 1)
+       while (safe_read (READ_SIDE (handle), &character, 1) == 1)
          if (character == '\n')
            break;
       }
@@ -259,7 +262,7 @@ get_status_off (int handle)
     }
 }
 
-#if HAVE_NETDB_H
+#if WITH_REXEC
 
 /*-------------------------------------------------------------------------.
 | Execute /etc/rmt as user USER on remote system HOST using rexec.  Return |
@@ -276,8 +279,8 @@ get_status_off (int handle)
 static int
 _rmt_rexec (char *host, char *user)
 {
-  int saved_stdin = dup (fileno (stdin));
-  int saved_stdout = dup (fileno (stdout));
+  int saved_stdin = dup (STDIN_FILENO);
+  int saved_stdout = dup (STDOUT_FILENO);
   struct servent *rexecserv;
   int result;
 
@@ -307,7 +310,7 @@ _rmt_rexec (char *host, char *user)
   return result;
 }
 
-#endif /* HAVE_NETDB_H */
+#endif /* WITH_REXEC */
 
 /*------------------------------------------------------------------------.
 | Open a file (a magnetic tape device?) on the system specified in PATH,  |
@@ -380,7 +383,7 @@ rmt_open__ (const char *path, int open_mode, int bias, const char *remote_shell)
   if (remote_user && *remote_user == '\0')
     remote_user = NULL;
 
-#if HAVE_NETDB_H
+#if WITH_REXEC
 
   /* Execute the remote command using rexec.  */
 
@@ -393,7 +396,7 @@ rmt_open__ (const char *path, int open_mode, int bias, const char *remote_shell)
 
   WRITE_SIDE (remote_pipe_number) = READ_SIDE (remote_pipe_number);
 
-#else /* not HAVE_NETDB_H */
+#else /* not WITH_REXEC */
   {
     const char *remote_shell_basename;
     pid_t status;
@@ -410,7 +413,7 @@ rmt_open__ (const char *path, int open_mode, int bias, const char *remote_shell)
        return -1;
 #endif
       }
-    remote_shell_basename = strrchr (remote_shell, '/');
+    remote_shell_basename = base_name (remote_shell);
     if (remote_shell_basename)
       remote_shell_basename++;
     else
@@ -436,12 +439,12 @@ rmt_open__ (const char *path, int open_mode, int bias, const char *remote_shell)
       {
        /* Child.  */
 
-       close (0);
+       close (STDIN_FILENO);
        dup (to_remote[remote_pipe_number][PREAD]);
        close (to_remote[remote_pipe_number][PREAD]);
        close (to_remote[remote_pipe_number][PWRITE]);
 
-       close (1);
+       close (STDOUT_FILENO);
        dup (from_remote[remote_pipe_number][PWRITE]);
        close (from_remote[remote_pipe_number][PREAD]);
        close (from_remote[remote_pipe_number][PWRITE]);
@@ -469,7 +472,7 @@ rmt_open__ (const char *path, int open_mode, int bias, const char *remote_shell)
     close (from_remote[remote_pipe_number][PWRITE]);
     close (to_remote[remote_pipe_number][PREAD]);
   }
-#endif /* not HAVE_NETDB_H */
+#endif /* not WITH_REXEC */
 
   /* Attempt to open the tape device.  */
 
@@ -527,7 +530,7 @@ rmt_read__ (int handle, char *buffer, size_t length)
 
   for (counter = 0; counter < status; counter += rlen, buffer += rlen)
     {
-      rlen = read (READ_SIDE (handle), buffer, status - counter);
+      rlen = safe_read (READ_SIDE (handle), buffer, status - counter);
       if (rlen <= 0)
        {
          _rmt_shutdown (handle, EIO);
@@ -554,7 +557,7 @@ rmt_write__ (int handle, char *buffer, size_t length)
     return -1;
 
   pipe_handler = signal (SIGPIPE, SIG_IGN);
-  if (write (WRITE_SIDE (handle), buffer, length) == length)
+  if (full_write (WRITE_SIDE (handle), buffer, length) == length)
     {
       signal (SIGPIPE, pipe_handler);
       return get_status (handle);
@@ -586,6 +589,14 @@ rmt_lseek__ (int handle, off_t offset, int whence)
   if (offset < 0)
     *--p = '-';
 
+  switch (whence)
+    {
+    case SEEK_SET: whence = 0; break;
+    case SEEK_CUR: whence = 1; break;
+    case SEEK_END: whence = 2; break;
+    default: abort ();
+    }
+
   sprintf (command_buffer, "L%s\n%d\n", p, whence);
 
   if (do_command (handle, command_buffer) == -1)
@@ -653,7 +664,8 @@ rmt_ioctl__ (int handle, int operation, char *argument)
 
        for (; status > 0; status -= counter, argument += counter)
          {
-           counter = read (READ_SIDE (handle), argument, (size_t) status);
+           counter = safe_read (READ_SIDE (handle),
+                                argument, (size_t) status);
            if (counter <= 0)
              {
                _rmt_shutdown (handle, EIO);
This page took 0.030621 seconds and 4 git commands to generate.