int deref_stat (char const *name, struct stat *buf);
-size_t blocking_read (int fd, void *buf, size_t count);
-size_t blocking_write (int fd, void const *buf, size_t count);
+ptrdiff_t blocking_read (int fd, void *buf, idx_t count);
+idx_t blocking_write (int fd, void const *buf, idx_t count);
extern idx_t chdir_current;
extern int chdir_fd;
#define WARNOPT(opt,args) \
do \
{ \
- if (WARNING_ENABLED(opt)) WARN (args); \
+ if (WARNING_ENABLED (opt)) WARN (args); \
} \
while (0)
}
/* Take a buffer returned by read_and_process and do nothing with it. */
-static int
-process_noop (MAYBE_UNUSED size_t size, MAYBE_UNUSED char *data)
+static bool
+process_noop (MAYBE_UNUSED idx_t size, MAYBE_UNUSED char *data)
{
- return 1;
+ return true;
}
-static int
-process_rawdata (size_t bytes, char *buffer)
+static bool
+process_rawdata (idx_t bytes, char *buffer)
{
- size_t status = blocking_read (diff_handle, diff_buffer, bytes);
+ ptrdiff_t status = blocking_read (diff_handle, diff_buffer, bytes);
if (status != bytes)
{
- if (status == SAFE_READ_ERROR)
+ if (status < 0)
{
read_error (current_stat_info.file_name);
report_difference (¤t_stat_info, NULL);
else
{
report_difference (¤t_stat_info,
- ngettext ("Could only read %lu of %lu byte",
- "Could only read %lu of %lu bytes",
+ ngettext ("Could read only %td of %td byte",
+ "Could read only %td of %td bytes",
bytes),
- (unsigned long) status, (unsigned long) bytes);
+ status, bytes);
}
- return 0;
+ return false;
}
if (memcmp (buffer, diff_buffer, bytes))
{
report_difference (¤t_stat_info, _("Contents differ"));
- return 0;
+ return false;
}
- return 1;
+ return true;
}
/* Some other routine wants SIZE bytes in the archive. For each chunk
of the archive, call PROCESSOR with the size of the chunk, and the
- address of the chunk it can work with. The PROCESSOR should return
- nonzero for success. Once it returns error, continue skipping
- without calling PROCESSOR anymore. */
+ address of the chunk it can work with. PROCESSOR should return
+ true for success. Once it fails, continue skipping without calling
+ PROCESSOR anymore. */
static void
-read_and_process (struct tar_stat_info *st, int (*processor) (size_t, char *))
+read_and_process (struct tar_stat_info *st, bool (*processor) (idx_t, char *))
{
union block *data_block;
size_t data_size;
mv_begin_write (st->file_name, st->stat.st_size, st->stat.st_size);
while (size_left > 0)
{
- size_t bufsize, count;
-
blk = find_next_block ();
- bufsize = available_space_after (blk);
+ idx_t bufsize = available_space_after (blk);
if (size_left < bufsize)
{
/* Last read -- zero out area beyond. */
bufsize = size_left;
- count = bufsize % BLOCKSIZE;
- if (count)
- memset (blk->buffer + size_left, 0, BLOCKSIZE - count);
+ idx_t beyond = bufsize % BLOCKSIZE;
+ if (beyond)
+ memset (blk->buffer + size_left, 0, BLOCKSIZE - beyond);
}
- count = (fd <= 0) ? bufsize : blocking_read (fd, blk->buffer, bufsize);
- if (count == SAFE_READ_ERROR)
+ ptrdiff_t count;
+ if (fd <= 0)
+ count = bufsize;
+ else
{
- read_diag_details (st->orig_file_name,
- st->stat.st_size - size_left, bufsize);
- pad_archive (size_left);
- return dump_status_short;
+ count = blocking_read (fd, blk->buffer, bufsize);
+ if (count < 0)
+ {
+ read_diag_details (st->orig_file_name,
+ st->stat.st_size - size_left, bufsize);
+ pad_archive (size_left);
+ return dump_status_short;
+ }
}
size_left -= count;
set_next_block_after (blk + (bufsize - 1) / BLOCKSIZE);
off_t size;
union block *data_block;
int status;
- size_t count;
size_t written;
bool interdir_made = false;
mode_t mode = (current_stat_info.stat.st_mode & MODE_RWX
if (written > size)
written = size;
errno = 0;
- count = blocking_write (fd, data_block->buffer, written);
+ idx_t count = blocking_write (fd, data_block->buffer, written);
size -= written;
set_next_block_after ((union block *)
opened O_NONBLOCK for security reasons, and on some file systems
this can cause read to fail with errno == EAGAIN. Return the
actual number of bytes read, zero for EOF, or
- SAFE_READ_ERROR upon error. */
-size_t
-blocking_read (int fd, void *buf, size_t count)
+ -1 upon error. */
+ptrdiff_t
+blocking_read (int fd, void *buf, idx_t count)
{
size_t bytes = full_read (fd, buf, count);
}
#endif
- if (bytes == 0 && errno != 0)
- bytes = SAFE_READ_ERROR;
- return bytes;
+ return bytes == SAFE_READ_ERROR || (bytes == 0 && errno != 0) ? -1 : bytes;
}
/* Write to FD from the buffer BUF with COUNT bytes. Do a full write.
files are opened O_NONBLOCK for security reasons, and on some file
systems this can cause write to fail with errno == EAGAIN. Return
the actual number of bytes written, setting errno if that is less
- than COUNT. */
-size_t
-blocking_write (int fd, void const *buf, size_t count)
+ than COUNT. Return -1 on write error. */
+idx_t
+blocking_write (int fd, void const *buf, idx_t count)
{
- size_t bytes = full_write (fd, buf, count);
+ idx_t bytes = full_write (fd, buf, count);
#if defined F_SETFL && O_NONBLOCK
if (bytes < count && errno == EAGAIN)
{
if (ignore_failed_read_option)
{
- if (WARNING_ENABLED(WARN_FAILED_READ))
+ if (WARNING_ENABLED (WARN_FAILED_READ))
close_warn (name);
}
else
{
if (ignore_failed_read_option)
{
- if (WARNING_ENABLED(WARN_FAILED_READ))
+ if (WARNING_ENABLED (WARN_FAILED_READ))
open_warn (name);
}
else
{
if (ignore_failed_read_option)
{
- if (WARNING_ENABLED(WARN_FAILED_READ))
+ if (WARNING_ENABLED (WARN_FAILED_READ))
read_warn_details (name, offset, size);
}
else
{
if (ignore_failed_read_option)
{
- if (WARNING_ENABLED(WARN_FAILED_READ))
+ if (WARNING_ENABLED (WARN_FAILED_READ))
readlink_warn (name);
}
else
{
if (ignore_failed_read_option)
{
- if (WARNING_ENABLED(WARN_FAILED_READ))
+ if (WARNING_ENABLED (WARN_FAILED_READ))
savedir_warn (name);
}
else
{
if (ignore_failed_read_option)
{
- if (WARNING_ENABLED(WARN_FAILED_READ))
+ if (WARNING_ENABLED (WARN_FAILED_READ))
seek_warn_details (name, offset);
}
else
{
if (ignore_failed_read_option)
{
- if (WARNING_ENABLED(WARN_FAILED_READ))
+ if (WARNING_ENABLED (WARN_FAILED_READ))
stat_warn (name);
}
else
struct tar_stat_info *st = file->stat_info;
int fd = file->fd;
char buffer[BLOCKSIZE];
- size_t count = 0;
off_t offset = 0;
struct sp_array sp = {0, 0};
if (!tar_sparse_scan (file, scan_begin, NULL))
return false;
- while ((count = blocking_read (fd, buffer, sizeof buffer)) != 0
- && count != SAFE_READ_ERROR)
+ while (true)
{
+ ptrdiff_t count = blocking_read (fd, buffer, sizeof buffer);
+ if (count <= 0)
+ {
+ if (count < 0)
+ read_diag_details (st->orig_file_name, offset, sizeof buffer);
+ break;
+ }
+
/* Analyze the block. */
if (zero_block_p (buffer, count))
{
sp.offset = offset;
sparse_add_map (st, &sp);
- st->archive_file_size += count;
return tar_sparse_scan (file, scan_end, NULL);
}
}
else while (write_size > 0)
{
- size_t count;
size_t wrbytes = (write_size > BLOCKSIZE) ? BLOCKSIZE : write_size;
union block *blk = find_next_block ();
if (!blk)
}
set_next_block_after (blk);
file->dumped_size += BLOCKSIZE;
- count = blocking_write (file->fd, blk->buffer, wrbytes);
+ idx_t count = blocking_write (file->fd, blk->buffer, wrbytes);
write_size -= count;
mv_size_left (file->stat_info->archive_file_size - file->dumped_size);
file->offset += count;