chiark / gitweb /
io-util: add new IOVEC_INIT/IOVEC_MAKE macros
authorLennart Poettering <lennart@poettering.net>
Thu, 21 Sep 2017 11:52:34 +0000 (13:52 +0200)
committerSven Eden <yamakuzure@gmx.net>
Thu, 21 Sep 2017 11:52:34 +0000 (13:52 +0200)
commitfeab16e5e3c1fa3469405bde91b542e5dcf0aa40
treeb2f3a607b5d8808e313dbd3d12468f8ed1bf2a75
parentee0cefd5da6939c406f0d421d6115fac4dd78535
io-util: add new IOVEC_INIT/IOVEC_MAKE macros

This adds IOVEC_INIT() and IOVEC_MAKE() for initializing iovec structures
from a pointer and a size. On top of these IOVEC_INIT_STRING() and
IOVEC_MAKE_STRING() are added which take a string and automatically
determine the size of the string using strlen().

This patch removes the old IOVEC_SET_STRING() macro, given that
IOVEC_MAKE_STRING() is now useful for similar purposes. Note that the
old IOVEC_SET_STRING() invocations were two characters shorter than the
new ones using IOVEC_MAKE_STRING(), but I think the new syntax is more
readable and more generic as it simply resolves to a C99 literal
structure initialization. Moreover, we can use very similar syntax now
for initializing strings and pointer+size iovec entries. We canalso use
the new macros to initialize function parameters on-the-fly or array
definitions. And given that we shouldn't have so many ways to do the
same stuff, let's just settle on the new macros.

(This also converts some code to use _cleanup_ where dynamically
allocated strings were using IOVEC_SET_STRING() before, to modernize
things a bit)
src/basic/io-util.h
src/basic/log.c