X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Frtapelib.c;h=cfc64dadce8fbbb102187c924787bafbd6cf0ca4;hb=1027b8433048ffc23de9474beb7a80342741c7f2;hp=d02386b51e896b368aee0d7682f6f013dab09eec;hpb=b9ca9399a16c0e27c95511547612b0d334ee8b3a;p=chaz%2Ftar diff --git a/src/rtapelib.c b/src/rtapelib.c index d02386b..cfc64da 100644 --- a/src/rtapelib.c +++ b/src/rtapelib.c @@ -1,5 +1,5 @@ /* Functions for communicating with a remote tape drive. - Copyright (C) 1988, 1992, 1994, 1996 Free Software Foundation, Inc. + Copyright 1988, 1992, 1994, 1996, 1997, 1999 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,6 +32,9 @@ #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; } @@ -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; @@ -410,11 +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, '/'); - if (remote_shell_basename) - remote_shell_basename++; - else - remote_shell_basename = remote_shell; + remote_shell_basename = base_name (remote_shell); /* Set up the pipes for the `rsh' command, and fork. */ @@ -436,12 +435,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]); @@ -527,7 +526,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 +553,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 +585,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 +660,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);