Data Structures | Defines | Functions

/tmp/buildd/xz-utils-5.0.0/src/xz/file_io.h File Reference

I/O types and functions. More...

Data Structures

union  io_buf
struct  file_pair

Defines

#define IO_BUFFER_SIZE   8192

Functions

void io_init (void)
 Initialize the I/O module.
void io_no_sparse (void)
 Disable creation of sparse files when decompressing.
file_pairio_open_src (const char *src_name)
 Open the source file.
bool io_open_dest (file_pair *pair)
 Open the destination file.
void io_close (file_pair *pair, bool success)
 Closes the file descriptors and frees possible allocated memory.
size_t io_read (file_pair *pair, io_buf *buf, size_t size)
 Reads from the source file to a buffer.
bool io_pread (file_pair *pair, io_buf *buf, size_t size, off_t pos)
 Read from source file from given offset to a buffer.
bool io_write (file_pair *pair, const io_buf *buf, size_t size)
 Writes a buffer to the destination file.

Detailed Description

I/O types and functions.


Function Documentation

void io_init ( void   ) 

Initialize the I/O module.

void io_no_sparse ( void   ) 

Disable creation of sparse files when decompressing.

References try_sparse.

file_pair* io_open_src ( const char *  src_name  ) 
bool io_open_dest ( file_pair pair  ) 

Open the destination file.

References signals_block(), and signals_unblock().

Referenced by coder_run().

void io_close ( file_pair pair,
bool  success 
)

Closes the file descriptors and frees possible allocated memory.

The success argument determines if source or destination file gets unlinked:

  • false: The destination file is unlinked.
  • true: The source file is unlinked unless writing to stdout or --keep was used.

References file_pair::dest_fd, file_pair::dest_name, file_pair::dest_pending_sparse, file_pair::dest_try_sparse, io_close_dest(), io_close_src(), io_copy_attrs(), message_error(), signals_block(), and signals_unblock().

Referenced by coder_run(), and list_file().

size_t io_read ( file_pair pair,
io_buf buf,
size_t  size 
)

Reads from the source file to a buffer.

Parameters:
pair File pair having the source file open for reading
buf Destination buffer to hold the read data
size Size of the buffer; assumed be smaller than SSIZE_MAX
Returns:
On success, number of bytes read is returned. On end of file zero is returned and pair->src_eof set to true. On error, SIZE_MAX is returned and error message printed.

References message_error(), file_pair::src_eof, file_pair::src_fd, file_pair::src_name, and user_abort.

Referenced by coder_normal(), coder_passthru(), coder_run(), and io_pread().

bool io_pread ( file_pair pair,
io_buf buf,
size_t  size,
off_t  pos 
)

Read from source file from given offset to a buffer.

This is remotely similar to standard pread(). This uses lseek() though, so the read offset is changed on each call.

Parameters:
pair Seekable source file
buf Destination buffer
size Amount of data to read
pos Offset relative to the beginning of the file, from which the data should be read.
Returns:
On success, false is returned. On error, error message is printed and true is returned.

References io_read(), message_error(), file_pair::src_fd, and file_pair::src_name.

Referenced by parse_block_header(), parse_check_value(), and parse_indexes().

bool io_write ( file_pair pair,
const io_buf buf,
size_t  size 
)

Writes a buffer to the destination file.

Parameters:
pair File pair having the destination file open for writing
buf Buffer containing the data to be written
size Size of the buffer; assumed be smaller than SSIZE_MAX
Returns:
On success, zero is returned. On error, -1 is returned and error message printed.

References file_pair::dest_fd, file_pair::dest_name, file_pair::dest_pending_sparse, file_pair::dest_try_sparse, and message_error().

Referenced by coder_normal(), and coder_passthru().