]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/io-util.h
core: Record ExecMainStartTimestamp before forking
[thirdparty/systemd.git] / src / basic / io-util.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
c004493c
LP
2#pragma once
3
c4febde9 4#include <poll.h>
c004493c 5#include <stdbool.h>
11c3a366
TA
6#include <stddef.h>
7#include <stdint.h>
afc5dbf3 8#include <sys/types.h>
c004493c 9
11c3a366 10#include "macro.h"
c004493c
LP
11#include "time-util.h"
12
13int flush_fd(int fd);
14
15ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll);
16int loop_read_exact(int fd, void *buf, size_t nbytes, bool do_poll);
e22c60a9
MY
17
18int loop_write_full(int fd, const void *buf, size_t nbytes, usec_t timeout);
19static inline int loop_write(int fd, const void *buf, size_t nbytes) {
20 return loop_write_full(fd, buf, nbytes, 0);
21}
c004493c
LP
22
23int pipe_eof(int fd);
24
c4febde9 25int ppoll_usec(struct pollfd *fds, size_t nfds, usec_t timeout);
c004493c
LP
26int fd_wait_for_event(int fd, int event, usec_t timeout);
27
28ssize_t sparse_write(int fd, const void *p, size_t sz, size_t run_length);
afc5dbf3 29
a90fb858
LP
30static inline bool FILE_SIZE_VALID(uint64_t l) {
31 /* ftruncate() and friends take an unsigned file size, but actually cannot deal with file sizes larger than
32 * 2^63 since the kernel internally handles it as signed value. This call allows checking for this early. */
33
34 return (l >> 63) == 0;
35}
36
37static inline bool FILE_SIZE_VALID_OR_INFINITY(uint64_t l) {
38
39 /* Same as above, but allows one extra value: -1 as indication for infinity. */
40
f5fbe71d 41 if (l == UINT64_MAX)
a90fb858
LP
42 return true;
43
44 return FILE_SIZE_VALID(l);
45
46}