diff options
author | Tom Gundersen <teg@jklm.no> | 2015-10-27 16:55:16 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2015-10-27 16:55:16 +0100 |
commit | 0d0696812980d8f41c54739ad73716a233a2fa7c (patch) | |
tree | 217d98308a3039e106efde5fd6a7b6a657916950 /src/basic/io-util.h | |
parent | f47fc3ffc4b69a00083a76308f777b52afb8efbf (diff) | |
parent | 7760171904ef007f19e8f46aa240a00e382d5b74 (diff) |
Merge pull request #1691 from poettering/util-lib-3
split up util.h and macro.h into even more bits
Diffstat (limited to 'src/basic/io-util.h')
-rw-r--r-- | src/basic/io-util.h | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/basic/io-util.h b/src/basic/io-util.h index ff7c2a9ac4..cd2aa75ad2 100644 --- a/src/basic/io-util.h +++ b/src/basic/io-util.h @@ -21,8 +21,9 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <sys/types.h> #include <stdbool.h> +#include <sys/types.h> +#include <sys/uio.h> #include "time-util.h" @@ -37,3 +38,39 @@ int pipe_eof(int fd); int fd_wait_for_event(int fd, int event, usec_t timeout); ssize_t sparse_write(int fd, const void *p, size_t sz, size_t run_length); + +#define IOVEC_SET_STRING(i, s) \ + do { \ + struct iovec *_i = &(i); \ + char *_s = (char *)(s); \ + _i->iov_base = _s; \ + _i->iov_len = strlen(_s); \ + } while(false) + +static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, unsigned n) { + unsigned j; + size_t r = 0; + + for (j = 0; j < n; j++) + r += i[j].iov_len; + + return r; +} + +static inline size_t IOVEC_INCREMENT(struct iovec *i, unsigned n, size_t k) { + unsigned j; + + for (j = 0; j < n; j++) { + size_t sub; + + if (_unlikely_(k <= 0)) + break; + + sub = MIN(i[j].iov_len, k); + i[j].iov_len -= sub; + i[j].iov_base = (uint8_t*) i[j].iov_base + sub; + k -= sub; + } + + return k; +} |