]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
c004493c LP |
2 | #pragma once |
3 | ||
0c15577a | 4 | #include "forward.h" |
c004493c LP |
5 | |
6 | int flush_fd(int fd); | |
7 | ||
8 | ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll); | |
9 | int loop_read_exact(int fd, void *buf, size_t nbytes, bool do_poll); | |
e22c60a9 | 10 | |
6da2ea9f | 11 | int loop_write_full(int fd, const void *buf, size_t nbytes, usec_t timeout) _nonnull_if_nonzero_(2, 3); |
e22c60a9 MY |
12 | static inline int loop_write(int fd, const void *buf, size_t nbytes) { |
13 | return loop_write_full(fd, buf, nbytes, 0); | |
14 | } | |
c004493c LP |
15 | |
16 | int pipe_eof(int fd); | |
17 | ||
fa6f4484 JW |
18 | int ppoll_usec_full(struct pollfd *fds, size_t n_fds, usec_t timeout, const sigset_t *ss) _nonnull_if_nonzero_(1, 2); |
19 | _nonnull_if_nonzero_(1, 2) static inline int ppoll_usec(struct pollfd *fds, size_t n_fds, usec_t timeout) { | |
20 | return ppoll_usec_full(fds, n_fds, timeout, NULL); | |
789f4f7e LP |
21 | } |
22 | ||
c004493c LP |
23 | int fd_wait_for_event(int fd, int event, usec_t timeout); |
24 | ||
25 | ssize_t sparse_write(int fd, const void *p, size_t sz, size_t run_length); | |
afc5dbf3 | 26 | |
a90fb858 LP |
27 | static inline bool FILE_SIZE_VALID(uint64_t l) { |
28 | /* ftruncate() and friends take an unsigned file size, but actually cannot deal with file sizes larger than | |
29 | * 2^63 since the kernel internally handles it as signed value. This call allows checking for this early. */ | |
30 | ||
31 | return (l >> 63) == 0; | |
32 | } | |
33 | ||
34 | static inline bool FILE_SIZE_VALID_OR_INFINITY(uint64_t l) { | |
35 | ||
36 | /* Same as above, but allows one extra value: -1 as indication for infinity. */ | |
37 | ||
f5fbe71d | 38 | if (l == UINT64_MAX) |
a90fb858 LP |
39 | return true; |
40 | ||
41 | return FILE_SIZE_VALID(l); | |
a90fb858 | 42 | } |