#include "private.h"
#include <fcntl.h>
#include "open_stdxxx.h"
Defines | |
#define | O_BINARY 0 |
#define | O_NOCTTY 0 |
Functions | |
void | io_init (void) |
Initialize the I/O module. | |
static void | io_unlink (const char *name, const struct stat *known_st) |
Unlinks a file. | |
static void | io_copy_attrs (const file_pair *pair) |
Copies owner/group and permissions. | |
static bool | io_open_src (file_pair *pair) |
Opens the source file. Returns false on success, true on error. | |
static void | io_close_src (file_pair *pair, bool success) |
Closes source file of the file_pair structure. | |
static bool | io_open_dest (file_pair *pair) |
static int | io_close_dest (file_pair *pair, bool success) |
Closes destination file of the file_pair structure. | |
file_pair * | io_open (const char *src_name) |
Opens a file pair. | |
void | io_close (file_pair *pair, bool success) |
Closes the file descriptors and frees possible allocated memory. | |
size_t | io_read (file_pair *pair, uint8_t *buf, size_t size) |
Reads from the source file to a buffer. | |
bool | io_write (const file_pair *pair, const uint8_t *buf, size_t size) |
Writes a buffer to the destination file. | |
Variables | |
static bool | warn_fchown |
void io_init | ( | void | ) |
Initialize the I/O module.
static void io_unlink | ( | const char * | name, | |
const struct stat * | known_st | |||
) | [static] |
Unlinks a file.
This tries to verify that the file being unlinked really is the file that we want to unlink by verifying device and inode numbers. There's still a small unavoidable race, but this is much better than nothing (the file could have been moved/replaced even hours earlier).
Referenced by io_close_dest(), and io_close_src().
static void io_copy_attrs | ( | const file_pair * | pair | ) | [static] |
static bool io_open_src | ( | file_pair * | pair | ) | [static] |
Opens the source file. Returns false on success, true on error.
References signals_block(), signals_unblock(), and user_abort.
Referenced by io_open().
static void io_close_src | ( | file_pair * | pair, | |
bool | success | |||
) | [static] |
Closes source file of the file_pair structure.
pair | File whose src_fd should be closed | |
success | If true, the file will be removed from the disk if closing succeeds and --keep hasn't been used. |
References io_unlink().
Referenced by io_close(), and io_open().
static int io_close_dest | ( | file_pair * | pair, | |
bool | success | |||
) | [static] |
Closes destination file of the file_pair structure.
pair | File whose dest_fd should be closed | |
success | If false, the file will be removed from the disk. |
References io_unlink().
Referenced by io_close().
file_pair* io_open | ( | const char * | src_name | ) |
Opens a file pair.
References io_close_src(), io_open_src(), is_empty_filename(), signals_block(), signals_unblock(), and user_abort.
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:
References io_close_dest(), io_close_src(), io_copy_attrs(), signals_block(), and signals_unblock().
size_t io_read | ( | file_pair * | pair, | |
uint8_t * | buf, | |||
size_t | size | |||
) |
Reads from the source file to a buffer.
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 |
References user_abort.
bool io_write | ( | const file_pair * | pair, | |
const uint8_t * | buf, | |||
size_t | size | |||
) |
Writes a buffer to the destination file.
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 |
References user_abort.