]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
iovec-util: add iovec_is_valid() helper
authorLennart Poettering <lennart@poettering.net>
Mon, 20 Nov 2023 16:06:06 +0000 (17:06 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 5 Jan 2024 10:10:22 +0000 (11:10 +0100)
src/basic/iovec-util.h

index 038f342fb2d2060519c0e9108c37c3e97e754631..bbd10e2a676a97bee91e321860dcc70cff83c91b 100644 (file)
@@ -45,9 +45,15 @@ static inline void iovec_done_erase(struct iovec *iovec) {
 }
 
 static inline bool iovec_is_set(const struct iovec *iovec) {
+        /* Checks if the iovec points to a non-empty chunk of memory */
         return iovec && iovec->iov_len > 0 && iovec->iov_base;
 }
 
+static inline bool iovec_is_valid(const struct iovec *iovec) {
+        /* Checks if the iovec is either NULL, empty or points to a valid bit of memory */
+        return !iovec || (iovec->iov_base || iovec->iov_len == 0);
+}
+
 char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value);
 char* set_iovec_string_field_free(struct iovec *iovec, size_t *n_iovec, const char *field, char *value);