From afc5dbf37fd2399d37976388d9dd9ab470ecf446 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 27 Oct 2015 01:02:30 +0100 Subject: [PATCH] io-util.h: move iovec stuff from macro.h to io-util.h --- src/basic/io-util.h | 39 ++++++++++++++++++++++++++++++++++- src/basic/log.c | 1 + src/basic/macro.h | 41 ++----------------------------------- src/core/show-status.c | 1 + src/journal/coredump.c | 1 + src/journal/journald-audit.c | 3 ++- src/journal/journald-console.c | 1 + src/journal/journald-kmsg.c | 1 + src/journal/journald-native.c | 1 + src/journal/journald-server.c | 1 + src/journal/journald-stream.c | 1 + src/journal/journald-syslog.c | 1 + src/libsystemd/sd-bus/bus-message.c | 1 + src/resolve/resolved-dns-stream.c | 1 + 14 files changed, 53 insertions(+), 41 deletions(-) diff --git a/src/basic/io-util.h b/src/basic/io-util.h index ff7c2a9..cd2aa75 100644 --- a/src/basic/io-util.h +++ b/src/basic/io-util.h @@ -21,8 +21,9 @@ along with systemd; If not, see . ***/ -#include #include +#include +#include #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; +} diff --git a/src/basic/log.c b/src/basic/log.c index c99746f..4583cb8 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -33,6 +33,7 @@ #include "fd-util.h" #include "formats-util.h" +#include "io-util.h" #include "log.h" #include "macro.h" #include "missing.h" diff --git a/src/basic/macro.h b/src/basic/macro.h index 44ae1f1..c9bbe8d 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -22,11 +22,10 @@ ***/ #include -#include -#include -#include #include #include +#include +#include #define _printf_(a,b) __attribute__ ((format (printf, a, b))) #define _alloc_(...) __attribute__ ((alloc_size(__VA_ARGS__))) @@ -302,42 +301,6 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) { #define char_array_0(x) x[sizeof(x)-1] = 0; -#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; -} - #define VA_FORMAT_ADVANCE(format, ap) \ do { \ int _argtypes[128]; \ diff --git a/src/core/show-status.c b/src/core/show-status.c index 91f8f8e..81166ab 100644 --- a/src/core/show-status.c +++ b/src/core/show-status.c @@ -20,6 +20,7 @@ ***/ #include "fd-util.h" +#include "io-util.h" #include "parse-util.h" #include "show-status.h" #include "string-util.h" diff --git a/src/journal/coredump.c b/src/journal/coredump.c index b9ece73..f32e2d4 100644 --- a/src/journal/coredump.c +++ b/src/journal/coredump.c @@ -45,6 +45,7 @@ #include "fd-util.h" #include "fileio.h" #include "fs-util.h" +#include "io-util.h" #include "journald-native.h" #include "log.h" #include "macro.h" diff --git a/src/journal/journald-audit.c b/src/journal/journald-audit.c index 289f9bf..6a8ef7d 100644 --- a/src/journal/journald-audit.c +++ b/src/journal/journald-audit.c @@ -21,9 +21,10 @@ #include "audit-type.h" #include "fd-util.h" +#include "hexdecoct.h" +#include "io-util.h" #include "journald-audit.h" #include "missing.h" -#include "hexdecoct.h" #include "string-util.h" typedef struct MapField { diff --git a/src/journal/journald-console.c b/src/journal/journald-console.c index 4a5e07e..9acc324 100644 --- a/src/journal/journald-console.c +++ b/src/journal/journald-console.c @@ -26,6 +26,7 @@ #include "fd-util.h" #include "fileio.h" #include "formats-util.h" +#include "io-util.h" #include "journald-console.h" #include "journald-server.h" #include "parse-util.h" diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c index e680aaf..52e1fbe 100644 --- a/src/journal/journald-kmsg.c +++ b/src/journal/journald-kmsg.c @@ -31,6 +31,7 @@ #include "escape.h" #include "fd-util.h" #include "formats-util.h" +#include "io-util.h" #include "journald-kmsg.h" #include "journald-server.h" #include "journald-syslog.h" diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c index e427f20..9f3b1e3 100644 --- a/src/journal/journald-native.c +++ b/src/journal/journald-native.c @@ -26,6 +26,7 @@ #include "fd-util.h" #include "fs-util.h" +#include "io-util.h" #include "journald-console.h" #include "journald-kmsg.h" #include "journald-native.h" diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 32d1f36..03cc074 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -44,6 +44,7 @@ #include "fs-util.h" #include "hashmap.h" #include "hostname-util.h" +#include "io-util.h" #include "journal-authenticate.h" #include "journal-file.h" #include "journal-internal.h" diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index 8d9c416..de4f4d9 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -33,6 +33,7 @@ #include "escape.h" #include "fd-util.h" #include "fileio.h" +#include "io-util.h" #include "journald-console.h" #include "journald-kmsg.h" #include "journald-server.h" diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c index 488cccb..d0c4a41 100644 --- a/src/journal/journald-syslog.c +++ b/src/journal/journald-syslog.c @@ -27,6 +27,7 @@ #include "fd-util.h" #include "formats-util.h" +#include "io-util.h" #include "journald-console.h" #include "journald-kmsg.h" #include "journald-server.h" diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c index 447e25d..d5a6ad5 100644 --- a/src/libsystemd/sd-bus/bus-message.c +++ b/src/libsystemd/sd-bus/bus-message.c @@ -32,6 +32,7 @@ #include "bus-type.h" #include "bus-util.h" #include "fd-util.h" +#include "io-util.h" #include "memfd-util.h" #include "string-util.h" #include "strv.h" diff --git a/src/resolve/resolved-dns-stream.c b/src/resolve/resolved-dns-stream.c index b2eebe0..1150c30 100644 --- a/src/resolve/resolved-dns-stream.c +++ b/src/resolve/resolved-dns-stream.c @@ -22,6 +22,7 @@ #include #include "fd-util.h" +#include "io-util.h" #include "missing.h" #include "resolved-dns-stream.h" -- 2.7.4