Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
file_io.h File Reference

I/O types and functions. More...

Go to the source code of this file.

Data Structures

union  io_buf
 
struct  file_pair
 

Macros

#define IO_BUFFER_SIZE   8192
 

Functions

void io_init (void)
 Initialize the I/O module.
 
void io_write_to_user_abort_pipe (void)
 Write a byte to user_abort_pipe[1].
 
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.
 
void io_fix_src_pos (file_pair *pair, size_t rewind_size)
 Fix the position in src_fd.
 
bool io_seek_src (file_pair *pair, uint64_t pos)
 Seek to the given absolute position in the source file.
 
bool io_pread (file_pair *pair, io_buf *buf, size_t size, uint64_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.

Macro Definition Documentation

◆ IO_BUFFER_SIZE

#define IO_BUFFER_SIZE   8192

Function Documentation

◆ io_close()

void io_close ( file_pair * pair,
bool success )
extern

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.

◆ io_fix_src_pos()

void io_fix_src_pos ( file_pair * pair,
size_t rewind_size )
extern

Fix the position in src_fd.

This is used when –single-thream has been specified and decompression is successful. If the input file descriptor supports seeking, this function fixes the input position to point to the next byte after the decompressed stream.

Parameters
pairFile pair having the source file open for reading
rewind_sizeHow many bytes of extra have been read i.e. how much to seek backwards.

◆ io_init()

void io_init ( void )
extern

Initialize the I/O module.

◆ io_no_sparse()

void io_no_sparse ( void )
extern

Disable creation of sparse files when decompressing.

◆ io_open_dest()

bool io_open_dest ( file_pair * pair)
extern

Open the destination file.

◆ io_open_src()

file_pair * io_open_src ( const char * src_name)
extern

Open the source file.

◆ io_pread()

bool io_pread ( file_pair * pair,
io_buf * buf,
size_t size,
uint64_t pos )
extern

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
pairSeekable source file
bufDestination buffer
sizeAmount of data to read
posOffset 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.

◆ io_read()

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

Reads from the source file to a buffer.

Parameters
pairFile pair having the source file open for reading
bufDestination buffer to hold the read data
sizeSize of the buffer; must be at most IO_BUFFER_SIZE
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.
Parameters
pairFile pair having the source file open for reading
bufDestination buffer to hold the read data
sizeSize 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.

◆ io_seek_src()

bool io_seek_src ( file_pair * pair,
uint64_t pos )
extern

Seek to the given absolute position in the source file.

This calls lseek() and also clears pair->src_eof.

Parameters
pairSeekable source file
posOffset 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.

◆ io_write()

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

Writes a buffer to the destination file.

Parameters
pairFile pair having the destination file open for writing
bufBuffer containing the data to be written
sizeSize of the buffer; must be at most IO_BUFFER_SIZE
Returns
On success, zero is returned. On error, -1 is returned and error message printed.
Parameters
pairFile pair having the destination file open for writing
bufBuffer containing the data to be written
sizeSize of the buffer; assumed be smaller than SSIZE_MAX
Returns
On success, zero is returned. On error, -1 is returned and error message printed.

◆ io_write_to_user_abort_pipe()

void io_write_to_user_abort_pipe ( void )
extern

Write a byte to user_abort_pipe[1].

This is called from a signal handler.