Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
file_io.h
Go to the documentation of this file.
1// SPDX-License-Identifier: 0BSD
2
4//
7//
8// Author: Lasse Collin
9//
11
12// Some systems have suboptimal BUFSIZ. Use a bit bigger value on them.
13// We also need that IO_BUFFER_SIZE is a multiple of 8 (sizeof(uint64_t))
14#if BUFSIZ <= 1024
15# define IO_BUFFER_SIZE 8192
16#else
17# define IO_BUFFER_SIZE (BUFSIZ & ~7U)
18#endif
19
20#ifdef _MSC_VER
21 // The first one renames both "struct stat" -> "struct _stat64"
22 // and stat() -> _stat64(). The documentation mentions only
23 // "struct __stat64", not "struct _stat64", but the latter
24 // works too.
25# define stat _stat64
26# define fstat _fstat64
27# define off_t __int64
28#endif
29
30
36typedef union {
37 uint8_t u8[IO_BUFFER_SIZE];
38 uint32_t u32[IO_BUFFER_SIZE / sizeof(uint32_t)];
39 uint64_t u64[IO_BUFFER_SIZE / sizeof(uint64_t)];
40} io_buf;
41
42
43typedef struct {
46 const char *src_name;
47
50 char *dest_name;
51
53 int src_fd;
54
56 int dest_fd;
57
59 bool src_eof;
60
63 bool src_has_seen_input;
64
66 bool flush_needed;
67
70 bool dest_try_sparse;
71
75 off_t dest_pending_sparse;
76
78 struct stat src_st;
79
81 struct stat dest_st;
82
83} file_pair;
84
85
87extern void io_init(void);
88
89
90#ifndef TUKLIB_DOSLIKE
94extern void io_write_to_user_abort_pipe(void);
95#endif
96
97
99extern void io_no_sparse(void);
100
101
103extern file_pair *io_open_src(const char *src_name);
104
105
107extern bool io_open_dest(file_pair *pair);
108
109
117extern void io_close(file_pair *pair, bool success);
118
119
129extern size_t io_read(file_pair *pair, io_buf *buf, size_t size);
130
131
142extern void io_fix_src_pos(file_pair *pair, size_t rewind_size);
143
144
155extern bool io_seek_src(file_pair *pair, uint64_t pos);
156
157
171extern bool io_pread(file_pair *pair, io_buf *buf, size_t size, uint64_t pos);
172
173
182extern bool io_write(file_pair *pair, const io_buf *buf, size_t size);
char buf[N_BUF]
Definition spewG.c:36
Definition file_io.h:34
Definition file_io.h:27
size_t size
Definition platform.h:559
void io_no_sparse(void)
Disable creation of sparse files when decompressing.
Definition file_io.c:151
file_pair * io_open_src(const char *src_name)
Open the source file.
Definition file_io.c:760
void io_write_to_user_abort_pipe(void)
Write a byte to user_abort_pipe[1].
Definition file_io.c:135
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.
Definition file_io.c:1234
bool io_write(file_pair *pair, const io_buf *buf, size_t size)
Writes a buffer to the destination file.
Definition file_io.c:1320
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:1016
void io_close(file_pair *pair, bool success)
Closes the file descriptors and frees possible allocated memory.
Definition file_io.c:1077
void io_fix_src_pos(file_pair *pair, size_t rewind_size)
Fix the position in src_fd.
Definition file_io.c:1126
bool io_seek_src(file_pair *pair, uint64_t pos)
Seek to the given absolute position in the source file.
Definition file_io.c:1211
#define IO_BUFFER_SIZE
Definition file_io.h:16
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:1141
unsigned char u8
Definition harness.c:16
uint64_t u64
Definition zstd_decompress.c:63
uint32_t u32
Definition zstd_decompress.c:62