File opening, unlinking, and closing. More...
#include "private.h"#include <fcntl.h>#include "tuklib_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) |
| Unlink 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 |
File opening, unlinking, and closing.
| void io_init | ( | void | ) |
Initialize the I/O module.
| static void io_unlink | ( | const char * | name, | |
| const struct stat * | known_st | |||
| ) | [static] |
Unlink 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).
References message_error().
Referenced by io_close_dest(), and io_close_src().
| static void io_copy_attrs | ( | const file_pair * | pair | ) | [static] |
Copies owner/group and permissions.
References file_pair::dest_fd, file_pair::dest_name, message_warning(), and file_pair::src_st.
Referenced by io_close().
| static bool io_open_src | ( | file_pair * | pair | ) | [static] |
Opens the source file. Returns false on success, true on error.
References message_error(), message_warning(), signals_block(), signals_unblock(), file_pair::src_fd, file_pair::src_name, file_pair::src_st, 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(), file_pair::src_fd, file_pair::src_name, and file_pair::src_st.
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 file_pair::dest_fd, file_pair::dest_name, file_pair::dest_st, io_unlink(), and message_error().
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(), file_pair::src_name, and user_abort.
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:
References file_pair::dest_fd, io_close_dest(), io_close_src(), io_copy_attrs(), signals_block(), and signals_unblock().
Referenced by coder_run().
| 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 message_error(), file_pair::src_eof, file_pair::src_fd, file_pair::src_name, and user_abort.
Referenced by coder_normal(), coder_passthru(), and coder_run().
| 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 file_pair::dest_fd, file_pair::dest_name, message_error(), and user_abort.
Referenced by coder_normal(), and coder_passthru().
1.6.1