bool write_archive_to_stdout;
-static void (*flush_write_ptr) (size_t);
+static void (*flush_write_ptr) (idx_t);
static void (*flush_read_ptr) (void);
\f
struct bufmap
{
struct bufmap *next; /* Pointer to the next map entry */
- size_t start; /* Offset of the first data block */
+ idx_t start; /* Offset of the first data block */
char *file_name; /* Name of the stored file */
off_t sizetotal; /* Size of the stored file */
off_t sizeleft; /* Size left to read/write */
- size_t nblocks; /* Number of blocks written since reset */
+ idx_t nblocks; /* Number of blocks written since reset */
};
static struct bufmap *bufmap_head, *bufmap_tail;
}
static struct bufmap *
-bufmap_locate (size_t off)
+bufmap_locate (idx_t off)
{
struct bufmap *map;
struct zip_magic
{
enum compress_type type;
- size_t length;
+ char length;
char const *magic;
};
through the end of the current buffer of blocks. This space is
available for filling with data, or taking data from. POINTER is
usually (but not always) the result of previous find_next_block call. */
-size_t
+idx_t
available_space_after (union block *pointer)
{
return record_end->buffer - pointer->buffer;
struct bufmap *map = bufmap_locate (status);
if (map)
{
- size_t delta = status - map->start * BLOCKSIZE;
- ptrdiff_t diff;
+ idx_t delta = status - map->start * BLOCKSIZE;
+ idx_t diff;
map->nblocks += delta / BLOCKSIZE;
if (delta > map->sizeleft)
delta = map->sizeleft;
}
static void
-short_read (size_t status)
+short_read (idx_t status)
{
- size_t left; /* bytes left */
+ idx_t left; /* bytes left */
char *more; /* pointer to next byte to read */
more = record_start->buffer + status;
void
flush_archive (void)
{
- size_t buffer_level;
+ idx_t buffer_level;
if (access_mode == ACCESS_READ && time_to_start_writing)
{
static bool
try_new_volume (void)
{
- size_t status;
+ ptrdiff_t status;
union block *header;
enum access_mode acc;
return true;
while ((status = rmtread (archive, record_start->buffer, record_size))
- == SAFE_READ_ERROR)
+ < 0)
archive_read_error ();
if (status != record_size)
{
int tmp;
union block *block = find_next_block ();
- size_t len = strlen (map->file_name);
+ idx_t len = strlen (map->file_name);
if (len > NAME_FIELD_SIZE)
{
static void
simple_flush_read (void)
{
- size_t status; /* result from system call */
-
checkpoint_run (false);
/* Clear the count of errors. This only applies to a single call to
if (write_archive_to_stdout && record_start_block != 0)
{
archive = STDOUT_FILENO;
- status = sys_write_archive_buffer ();
+ idx_t status = sys_write_archive_buffer ();
archive = STDIN_FILENO;
if (status != record_size)
archive_write_error (status);
}
- for (;;)
- {
- status = rmtread (archive, record_start->buffer, record_size);
- if (status == record_size)
- {
- records_read++;
- return;
- }
- if (status == SAFE_READ_ERROR)
- {
- archive_read_error ();
- continue; /* try again */
- }
- break;
- }
- short_read (status);
+ ptrdiff_t nread;
+ while ((nread = rmtread (archive, record_start->buffer, record_size)) < 0)
+ archive_read_error ();
+ if (nread == record_size)
+ records_read++;
+ else
+ short_read (nread);
}
/* Simple flush write (no multi-volume or label extensions) */
static void
-simple_flush_write (MAYBE_UNUSED size_t level)
+simple_flush_write (MAYBE_UNUSED idx_t level)
{
ssize_t status;
static void
_gnu_flush_read (void)
{
- size_t status; /* result from system call */
-
checkpoint_run (false);
/* Clear the count of errors. This only applies to a single call to
if (write_archive_to_stdout && record_start_block != 0)
{
archive = STDOUT_FILENO;
- status = sys_write_archive_buffer ();
+ idx_t status = sys_write_archive_buffer ();
archive = STDIN_FILENO;
if (status != record_size)
archive_write_error (status);
}
- for (;;)
+ ptrdiff_t nread;
+ while ((nread = rmtread (archive, record_start->buffer, record_size)) < 0
+ && ! (errno == ENOSPC && multi_volume_option))
+ archive_read_error ();
+ /* The condition below used to include
+ || (nread > 0 && !read_full_records)
+ This is incorrect since even if new_volume() succeeds, the
+ subsequent call to rmtread will overwrite the chunk of data
+ already read in the buffer, so the processing will fail */
+ if (nread <= 0 && multi_volume_option)
{
- status = rmtread (archive, record_start->buffer, record_size);
- if (status == record_size)
- {
- records_read++;
- return;
- }
-
- /* The condition below used to include
- || (status > 0 && !read_full_records)
- This is incorrect since even if new_volume() succeeds, the
- subsequent call to rmtread will overwrite the chunk of data
- already read in the buffer, so the processing will fail */
- if ((status == 0
- || (status == SAFE_READ_ERROR && errno == ENOSPC))
- && multi_volume_option)
- {
- while (!try_new_volume ())
- ;
- if (current_block == record_end)
- /* Necessary for blocking_factor == 1 */
- flush_archive();
- return;
- }
- else if (status == SAFE_READ_ERROR)
- {
- archive_read_error ();
- continue;
- }
- break;
+ while (!try_new_volume ())
+ continue;
+ if (current_block == record_end)
+ /* Necessary for blocking_factor == 1 */
+ flush_archive ();
}
- short_read (status);
+ else if (nread == record_size)
+ records_read++;
+ else
+ short_read (nread);
}
static void
}
static void
-_gnu_flush_write (size_t buffer_level)
+_gnu_flush_write (idx_t buffer_level)
{
ssize_t status;
union block *header;
char *copy_ptr;
- size_t copy_size;
- size_t bufsize;
+ idx_t copy_size;
+ idx_t bufsize;
struct bufmap *map;
status = _flush_write ();
}
static void
-gnu_flush_write (size_t buffer_level)
+gnu_flush_write (idx_t buffer_level)
{
flush_write_ptr = simple_flush_write; /* Avoid recursion */
_gnu_flush_write (buffer_level);