#define DEBUG_FORK 0 /* if nonzero, childs are born stopped */
-#define STDIN 0 /* standard input file descriptor */
-#define STDOUT 1 /* standard output file descriptor */
-
#define PREAD 0 /* read file descriptor from pipe() */
#define PWRITE 1 /* write file descriptor from pipe() */
program_name = _("tar (child)");
- xdup2 (parent_pipe[PREAD], STDIN, _("(child) Pipe to stdin"));
+ xdup2 (parent_pipe[PREAD], STDIN_FILENO, _("(child) Pipe to stdin"));
xclose (parent_pipe[PWRITE]);
/* Check if we need a grandchild tar. This happens only if either:
FATAL_ERROR ((0, saved_errno, _("Cannot open archive %s"),
archive_name_array[0]));
}
- xdup2 (archive, STDOUT, _("Archive to stdout"));
+ xdup2 (archive, STDOUT_FILENO, _("Archive to stdout"));
execlp (use_compress_program_option, use_compress_program_option,
(char *) 0);
FATAL_ERROR ((0, errno, _("Cannot exec %s"),
{
/* The child tar is still here! Launch the compressor. */
- xdup2 (child_pipe[PWRITE], STDOUT, _("((child)) Pipe to stdout"));
+ xdup2 (child_pipe[PWRITE], STDOUT_FILENO,
+ _("((child)) Pipe to stdout"));
xclose (child_pipe[PREAD]);
execlp (use_compress_program_option, use_compress_program_option,
(char *) 0);
/* Prepare for reblocking the data from the compressor into the archive. */
- xdup2 (child_pipe[PREAD], STDIN, _("(grandchild) Pipe to stdin"));
+ xdup2 (child_pipe[PREAD], STDIN_FILENO, _("(grandchild) Pipe to stdin"));
xclose (child_pipe[PWRITE]);
if (strcmp (archive_name_array[0], "-") == 0)
- archive = STDOUT;
+ archive = STDOUT_FILENO;
else
archive = rmtcreat (archive_name_array[0], 0666, rsh_command_option);
if (archive < 0)
if (size < BLOCKSIZE)
size = BLOCKSIZE;
- status = read (STDIN, cursor, size);
+ status = full_read (STDIN_FILENO, cursor, size);
if (status <= 0)
break;
}
program_name = _("tar (child)");
- xdup2 (parent_pipe[PWRITE], STDOUT, _("(child) Pipe to stdout"));
+ xdup2 (parent_pipe[PWRITE], STDOUT_FILENO, _("(child) Pipe to stdout"));
xclose (parent_pipe[PREAD]);
/* Check if we need a grandchild tar. This happens only if either:
if (archive < 0)
FATAL_ERROR ((0, errno, _("Cannot open archive %s"),
archive_name_array[0]));
- xdup2 (archive, STDIN, _("Archive to stdin"));
+ xdup2 (archive, STDIN_FILENO, _("Archive to stdin"));
execlp (use_compress_program_option, use_compress_program_option,
"-d", (char *) 0);
FATAL_ERROR ((0, errno, _("Cannot exec %s"),
{
/* The child tar is still here! Launch the uncompressor. */
- xdup2 (child_pipe[PREAD], STDIN, _("((child)) Pipe to stdin"));
+ xdup2 (child_pipe[PREAD], STDIN_FILENO, _("((child)) Pipe to stdin"));
xclose (child_pipe[PWRITE]);
execlp (use_compress_program_option, use_compress_program_option,
"-d", (char *) 0);
/* Prepare for unblocking the data from the archive into the uncompressor. */
- xdup2 (child_pipe[PWRITE], STDOUT, _("(grandchild) Pipe to stdout"));
+ xdup2 (child_pipe[PWRITE], STDOUT_FILENO, _("(grandchild) Pipe to stdout"));
xclose (child_pipe[PREAD]);
if (strcmp (archive_name_array[0], "-") == 0)
- archive = STDIN;
+ archive = STDIN_FILENO;
else
archive = rmtopen (archive_name_array[0], O_RDONLY | O_BINARY,
0666, rsh_command_option);
while (maximum)
{
count = maximum < BLOCKSIZE ? maximum : BLOCKSIZE;
- status = write (STDOUT, cursor, count);
+ status = full_write (STDOUT_FILENO, cursor, count);
if (status < 0)
FATAL_ERROR ((0, errno, _("\
Cannot write to compression program")));
switch (access)
{
case ACCESS_READ:
- archive = STDIN;
+ archive = STDIN_FILENO;
break;
case ACCESS_WRITE:
- archive = STDOUT;
+ archive = STDOUT_FILENO;
stdlis = stderr;
break;
case ACCESS_UPDATE:
- archive = STDIN;
+ archive = STDIN_FILENO;
stdlis = stderr;
write_archive_to_stdout = 1;
break;
if (!read_file && !info_script_option)
/* FIXME: if fopen is used, it will never be closed. */
- read_file = archive == STDIN ? fopen (TTY_NAME, "r") : stdin;
+ read_file = archive == STDIN_FILENO ? fopen (TTY_NAME, "r") : stdin;
if (now_verifying)
return 0;
init_sparsearray ();
clear_buffer (buffer);
- while (count = read (file, buffer, sizeof buffer), count != 0)
+ while (count = full_read (file, buffer, sizeof buffer), count != 0)
{
/* Realloc the scratch area as necessary. FIXME: should reallocate
only at beginning of a new instance of non-zero data. */
#if 0
if (amount_read)
{
- count = read (file, start->buffer + amount_read,
- BLOCKSIZE - amount_read);
+ count = full_read (file, start->buffer + amount_read,
+ BLOCKSIZE - amount_read);
bufsize -= BLOCKSIZE - amount_read;
amount_read = 0;
set_next_block_after (start);
#endif
/* Store the data. */
- count = read (file, start->buffer, BLOCKSIZE);
+ count = full_read (file, start->buffer, BLOCKSIZE);
if (count < 0)
{
char buf[UINTMAX_STRSIZE_BOUND];
char buffer[BLOCKSIZE];
clear_buffer (buffer);
- count = read (file, buffer, bufsize);
+ count = full_read (file, buffer, bufsize);
memcpy (start->buffer, buffer, BLOCKSIZE);
}
if (f < 0)
count = bufsize;
else
- count = read (f, start->buffer, bufsize);
+ count = full_read (f, start->buffer, bufsize);
if (count < 0)
{
char buf[UINTMAX_STRSIZE_BOUND];
written = sparsearray[sparse_ind++].numbytes;
while (written > BLOCKSIZE)
{
- count = write (fd, data_block->buffer, BLOCKSIZE);
+ count = full_write (fd, data_block->buffer, BLOCKSIZE);
if (count < 0)
ERROR ((0, errno, _("%s: Could not write to file"), name));
written -= count;
data_block = find_next_block ();
}
- count = write (fd, data_block->buffer, written);
+ count = full_write (fd, data_block->buffer, written);
if (count < 0)
ERROR ((0, errno, _("%s: Could not write to file"), name));
if (written > size)
written = size;
errno = 0; /* FIXME: errno should be read-only */
- sstatus = write (fd, data_block->buffer, written);
+ sstatus = full_write (fd, data_block->buffer, written);
set_next_block_after ((union block *)
(data_block->buffer + written - 1));
written
= SIZE_FROM_OCT (exhdr->sparse_header.sp[counter].numbytes);
lseek (fd, offset, 0);
- sstatus = write (fd, data_block->buffer, written);
+ sstatus = full_write (fd, data_block->buffer, written);
if (sstatus == written)
continue;
}
/* Remote connection server.
- Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
+ Copyright 1994, 1995, 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 the
static char *
private_strerror (int errnum)
{
- extern const char *const sys_errlist[];
+ extern char *sys_errlist[];
extern int sys_nerr;
if (errnum > 0 && errnum <= sys_nerr)
- return sys_errlist[errnum];
- return N_("Unknown system error");
+ return _(sys_errlist[errnum]);
+ return _("Unknown system error");
}
# define strerror private_strerror
#endif
DEBUG1 ("rmtd: E 0 (%s)\n", string);
sprintf (reply_buffer, "E0\n%s\n", string);
- write (1, reply_buffer, strlen (reply_buffer));
+ full_write (STDOUT_FILENO, reply_buffer, strlen (reply_buffer));
}
/*---.
DEBUG2 ("rmtd: E %d (%s)\n", num, strerror (num));
sprintf (reply_buffer, "E%d\n%s\n", num, strerror (num));
- write (1, reply_buffer, strlen (reply_buffer));
+ full_write (STDOUT_FILENO, reply_buffer, strlen (reply_buffer));
}
/*---.
for (counter = 0; counter < STRING_SIZE; counter++)
{
- if (read (0, string + counter, 1) != 1)
+ if (full_read (STDIN_FILENO, string + counter, 1) != 1)
exit (EXIT_SUCCESS);
if (string[counter] == '\n')
#ifdef SO_RCVBUF
while (size > 1024 &&
- setsockopt (0, SOL_SOCKET, SO_RCVBUF, (char *) &size, sizeof (size)) < 0)
+ (setsockopt (STDIN_FILENO, SOL_SOCKET, SO_RCVBUF,
+ (char *) &size, sizeof size)
+ < 0))
size -= 1024;
#else
/* FIXME: I do not see any purpose to the following line... Sigh! */
top:
errno = 0; /* FIXME: errno should be read-only */
status = 0;
- if (read (0, &command, 1) != 1)
+ if (full_read (STDIN_FILENO, &command, 1) != 1)
exit (EXIT_SUCCESS);
switch (command)
DEBUG1 ("rmtd: A %s\n", p);
sprintf (reply_buffer, "A%s\n", p);
- write (1, reply_buffer, strlen (reply_buffer));
+ full_write (STDOUT_FILENO, reply_buffer, strlen (reply_buffer));
goto top;
}
prepare_record_buffer (size);
for (counter = 0; counter < size; counter += status)
{
- status = read (0, &record_buffer[counter], size - counter);
+ status = full_read (STDIN_FILENO, &record_buffer[counter],
+ size - counter);
if (status <= 0)
{
DEBUG (_("rmtd: Premature eof\n"));
exit (EXIT_FAILURE); /* exit status used to be 2 */
}
}
- status = write (tape, record_buffer, size);
+ status = full_write (tape, record_buffer, size);
if (status < 0)
goto ioerror;
goto respond;
size = atol (count_string);
prepare_record_buffer (size);
- status = read (tape, record_buffer, size);
+ status = full_read (tape, record_buffer, size);
if (status < 0)
goto ioerror;
sprintf (reply_buffer, "A%ld\n", status);
- write (1, reply_buffer, strlen (reply_buffer));
- write (1, record_buffer, (size_t) status);
+ full_write (STDOUT_FILENO, reply_buffer, strlen (reply_buffer));
+ full_write (STDOUT_FILENO, record_buffer, (size_t) status);
goto top;
}
goto ioerror;
status = sizeof (operation);
sprintf (reply_buffer, "A%ld\n", status);
- write (1, reply_buffer, strlen (reply_buffer));
- write (1, (char *) &operation, sizeof (operation));
+ full_write (STDOUT_FILENO, reply_buffer, strlen (reply_buffer));
+ full_write (STDOUT_FILENO, (char *) &operation, sizeof (operation));
}
#endif
goto top;
DEBUG1 ("rmtd: A %ld\n", status);
sprintf (reply_buffer, "A%ld\n", status);
- write (1, reply_buffer, strlen (reply_buffer));
+ full_write (STDOUT_FILENO, reply_buffer, strlen (reply_buffer));
goto top;
ioerror:
#define rmtread(Fd, Buffer, Length) \
(_isrmt (Fd) ? rmt_read__ (Fd - __REM_BIAS, Buffer, Length) \
- : read (Fd, Buffer, Length))
+ : full_read (Fd, Buffer, Length))
#define rmtwrite(Fd, Buffer, Length) \
(_isrmt (Fd) ? rmt_write__ (Fd - __REM_BIAS, Buffer, Length) \
- : write (Fd, Buffer, Length))
+ : full_write (Fd, Buffer, Length))
#define rmtlseek(Fd, Offset, Where) \
(_isrmt (Fd) ? rmt_lseek__ (Fd - __REM_BIAS, Offset, Where) \
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;
counter < COMMAND_BUFFER_SIZE;
counter++, cursor++)
{
- if (read (READ_SIDE (handle), cursor, 1) != 1)
+ if (full_read (READ_SIDE (handle), cursor, 1) != 1)
{
_rmt_shutdown (handle, EIO);
return 0;
{
char character;
- while (read (READ_SIDE (handle), &character, 1) == 1)
+ while (full_read (READ_SIDE (handle), &character, 1) == 1)
if (character == '\n')
break;
}
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;
{
/* 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]);
for (counter = 0; counter < status; counter += rlen, buffer += rlen)
{
- rlen = read (READ_SIDE (handle), buffer, status - counter);
+ rlen = full_read (READ_SIDE (handle), buffer, status - counter);
if (rlen <= 0)
{
_rmt_shutdown (handle, EIO);
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);
for (; status > 0; status -= counter, argument += counter)
{
- counter = read (READ_SIDE (handle), argument, (size_t) status);
+ counter = full_read (READ_SIDE (handle),
+ argument, (size_t) status);
if (counter <= 0)
{
_rmt_shutdown (handle, EIO);
(size_t) (BLOCKSIZE - status));
}
- status = read (handle, start->buffer, buffer_size);
+ status = full_read (handle, start->buffer, buffer_size);
if (status < 0)
{
char buf[UINTMAX_STRSIZE_BOUND];