Rizin
unix-like reverse engineering framework and cli tools
file_io.h
Go to the documentation of this file.
1 //
5 //
6 // Author: Lasse Collin
7 //
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
10 //
12 
13 // Some systems have suboptimal BUFSIZ. Use a bit bigger value on them.
14 // We also need that IO_BUFFER_SIZE is a multiple of 8 (sizeof(uint64_t))
15 #if BUFSIZ <= 1024
16 # define IO_BUFFER_SIZE 8192
17 #else
18 # define IO_BUFFER_SIZE (BUFSIZ & ~7U)
19 #endif
20 
21 
27 typedef union {
31 } io_buf;
32 
33 
34 typedef struct {
37  const char *src_name;
38 
41  char *dest_name;
42 
44  int src_fd;
45 
47  int dest_fd;
48 
50  bool src_eof;
51 
55 
58 
62 
67 
69  struct stat src_st;
70 
72  struct stat dest_st;
73 
74 } file_pair;
75 
76 
78 extern void io_init(void);
79 
80 
81 #ifndef TUKLIB_DOSLIKE
85 extern void io_write_to_user_abort_pipe(void);
86 #endif
87 
88 
90 extern void io_no_sparse(void);
91 
92 
93 #ifdef ENABLE_SANDBOX
95 extern void io_allow_sandbox(void);
96 #endif
97 
98 
100 extern file_pair *io_open_src(const char *src_name);
101 
102 
104 extern bool io_open_dest(file_pair *pair);
105 
106 
114 extern void io_close(file_pair *pair, bool success);
115 
116 
126 extern size_t io_read(file_pair *pair, io_buf *buf, size_t size);
127 
128 
139 extern void io_fix_src_pos(file_pair *pair, size_t rewind_size);
140 
141 
155 extern bool io_pread(file_pair *pair, io_buf *buf, size_t size, off_t pos);
156 
157 
166 extern bool io_write(file_pair *pair, const io_buf *buf, size_t size);
void io_no_sparse(void)
Disable creation of sparse files when decompressing.
Definition: file_io.c:151
void io_write_to_user_abort_pipe(void)
Write a byte to user_abort_pipe[1].
Definition: file_io.c:135
bool io_write(file_pair *pair, const io_buf *buf, size_t size)
Writes a buffer to the destination file.
Definition: file_io.c:1275
void io_init(void)
Initialize the I/O module.
Definition: file_io.c:95
bool io_open_dest(file_pair *pair)
Open the destination file.
Definition: file_io.c:991
void io_close(file_pair *pair, bool success)
Closes the file descriptors and frees possible allocated memory.
Definition: file_io.c:1052
void io_fix_src_pos(file_pair *pair, size_t rewind_size)
Fix the position in src_fd.
Definition: file_io.c:1101
#define IO_BUFFER_SIZE
Definition: file_io.h:16
file_pair * io_open_src(const char *src_name)
Open the source file.
Definition: file_io.c:741
size_t io_read(file_pair *pair, io_buf *buf, size_t size)
Reads from the source file to a buffer.
Definition: file_io.c:1116
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.
Definition: file_io.c:1186
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
unsigned int uint32_t
Definition: sftypes.h:29
unsigned long uint64_t
Definition: sftypes.h:28
int off_t
Definition: sftypes.h:41
unsigned char uint8_t
Definition: sftypes.h:31
bool dest_try_sparse
Definition: file_io.h:61
bool flush_needed
For –flush-timeout: True when flushing is needed.
Definition: file_io.h:57
char * dest_name
Definition: file_io.h:41
off_t dest_pending_sparse
Definition: file_io.h:66
int dest_fd
File descriptor of the target file.
Definition: file_io.h:47
const char * src_name
Definition: file_io.h:37
int src_fd
File descriptor of the source file.
Definition: file_io.h:44
bool src_has_seen_input
Definition: file_io.h:54
bool src_eof
True once end of the source file has been detected.
Definition: file_io.h:50
Definition: sftypes.h:80
int pos
Definition: main.c:11
Definition: file_io.h:27