]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/io-util.h
machined: when the pool limit is set to infinity don't resize backing loopback file
[thirdparty/systemd.git] / src / basic / io-util.h
CommitLineData
c004493c
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3#pragma once
4
5/***
6 This file is part of systemd.
7
8 Copyright 2010 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22***/
23
c004493c 24#include <stdbool.h>
11c3a366
TA
25#include <stddef.h>
26#include <stdint.h>
afc5dbf3
LP
27#include <sys/types.h>
28#include <sys/uio.h>
c004493c 29
11c3a366 30#include "macro.h"
c004493c
LP
31#include "time-util.h"
32
33int flush_fd(int fd);
34
35ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll);
36int loop_read_exact(int fd, void *buf, size_t nbytes, bool do_poll);
37int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll);
38
39int pipe_eof(int fd);
40
41int fd_wait_for_event(int fd, int event, usec_t timeout);
42
43ssize_t sparse_write(int fd, const void *p, size_t sz, size_t run_length);
afc5dbf3
LP
44
45#define IOVEC_SET_STRING(i, s) \
46 do { \
47 struct iovec *_i = &(i); \
48 char *_s = (char *)(s); \
49 _i->iov_base = _s; \
50 _i->iov_len = strlen(_s); \
51 } while(false)
52
53static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, unsigned n) {
54 unsigned j;
55 size_t r = 0;
56
57 for (j = 0; j < n; j++)
58 r += i[j].iov_len;
59
60 return r;
61}
62
63static inline size_t IOVEC_INCREMENT(struct iovec *i, unsigned n, size_t k) {
64 unsigned j;
65
66 for (j = 0; j < n; j++) {
67 size_t sub;
68
69 if (_unlikely_(k <= 0))
70 break;
71
72 sub = MIN(i[j].iov_len, k);
73 i[j].iov_len -= sub;
74 i[j].iov_base = (uint8_t*) i[j].iov_base + sub;
75 k -= sub;
76 }
77
78 return k;
79}