diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-10-27 01:02:30 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-10-27 13:25:57 +0100 |
commit | afc5dbf37fd2399d37976388d9dd9ab470ecf446 (patch) | |
tree | a312c7639a12b021289f595c602a519d8c3a73af /src/basic | |
parent | ceee6d3a44a81bcf42b21b777302a226422b11a1 (diff) |
io-util.h: move iovec stuff from macro.h to io-util.h
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/io-util.h | 39 | ||||
-rw-r--r-- | src/basic/log.c | 1 | ||||
-rw-r--r-- | src/basic/macro.h | 41 |
3 files changed, 41 insertions, 40 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; +} diff --git a/src/basic/log.c b/src/basic/log.c index c99746f916..4583cb840f 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 44ae1f157a..c9bbe8df4b 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -22,11 +22,10 @@ ***/ #include <assert.h> -#include <sys/param.h> -#include <sys/types.h> -#include <sys/uio.h> #include <inttypes.h> #include <stdbool.h> +#include <sys/param.h> +#include <sys/types.h> #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]; \ |