• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 19020191358

02 Nov 2025 05:04PM UTC coverage: 72.222% (-0.02%) from 72.241%
19020191358

push

github

web-flow
Enhance docs for ukify and direct kernel boots (#39516)

305246 of 422650 relevant lines covered (72.22%)

1085243.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.95
/src/basic/iovec-wrapper.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <stdio.h>
4

5
#include "alloc-util.h"
6
#include "iovec-util.h"
7
#include "iovec-wrapper.h"
8
#include "string-util.h"
9

10
struct iovec_wrapper *iovw_new(void) {
9✔
11
        return new0(struct iovec_wrapper, 1);
9✔
12
}
13

14
void iovw_done(struct iovec_wrapper *iovw) {
25,357✔
15
        assert(iovw);
25,357✔
16

17
        iovw->iovec = mfree(iovw->iovec);
25,357✔
18
        iovw->count = 0;
25,357✔
19
}
25,357✔
20

21
void iovw_done_free(struct iovec_wrapper *iovw) {
27✔
22
        assert(iovw);
27✔
23

24
        FOREACH_ARRAY(i, iovw->iovec, iovw->count)
798✔
25
                iovec_done(i);
771✔
26

27
        iovw_done(iovw);
27✔
28
}
27✔
29

30
struct iovec_wrapper *iovw_free_free(struct iovec_wrapper *iovw) {
×
31
        if (!iovw)
×
32
                return NULL;
33

34
        iovw_done_free(iovw);
×
35
        return mfree(iovw);
×
36
}
37

38
struct iovec_wrapper *iovw_free(struct iovec_wrapper *iovw) {
×
39
        if (!iovw)
×
40
                return NULL;
41

42
        iovw_done(iovw);
×
43
        return mfree(iovw);
×
44
}
45

46
int iovw_put(struct iovec_wrapper *iovw, void *data, size_t len) {
635,515✔
47
        assert(iovw);
635,515✔
48

49
        if (len == 0)
635,515✔
50
                return 0;
51

52
        assert(data);
635,515✔
53

54
        if (iovw->count >= IOV_MAX)
635,515✔
55
                return -E2BIG;
56

57
        if (!GREEDY_REALLOC(iovw->iovec, iovw->count + 1))
635,515✔
58
                return -ENOMEM;
59

60
        iovw->iovec[iovw->count++] = IOVEC_MAKE(data, len);
635,515✔
61
        return 0;
635,515✔
62
}
63

64
int iovw_put_string_field_full(struct iovec_wrapper *iovw, bool replace, const char *field, const char *value) {
399✔
65
        _cleanup_free_ char *x = NULL;
399✔
66
        int r;
399✔
67

68
        assert(iovw);
399✔
69

70
        x = strjoin(field, value);
399✔
71
        if (!x)
399✔
72
                return -ENOMEM;
73

74
        if (replace)
399✔
75
                FOREACH_ARRAY(iovec, iovw->iovec, iovw->count)
80✔
76
                        if (memory_startswith(iovec->iov_base, iovec->iov_len, field)) {
80✔
77
                                iovec->iov_len = strlen(x);
3✔
78
                                free_and_replace(iovec->iov_base, x);
3✔
79
                                return 0;
3✔
80
                        }
81

82
        r = iovw_put(iovw, x, strlen(x));
396✔
83
        if (r >= 0)
396✔
84
                TAKE_PTR(x);
396✔
85

86
        return r;
87
}
88

89
int iovw_put_string_fieldf_full(struct iovec_wrapper *iovw, bool replace, const char *field, const char *format, ...) {
108✔
90
        _cleanup_free_ char *value = NULL;
108✔
91
        va_list ap;
108✔
92
        int r;
108✔
93

94
        assert(format);
108✔
95

96
        va_start(ap, format);
108✔
97
        r = vasprintf(&value, format, ap);
108✔
98
        va_end(ap);
108✔
99
        if (r < 0)
108✔
100
                return -ENOMEM;
101

102
        return iovw_put_string_field_full(iovw, replace, field, value);
108✔
103
}
104

105
int iovw_put_string_field_free(struct iovec_wrapper *iovw, const char *field, char *value) {
160✔
106
        _cleanup_free_ _unused_ char *free_ptr = value;
160✔
107

108
        return iovw_put_string_field(iovw, field, value);
160✔
109
}
110

111
void iovw_rebase(struct iovec_wrapper *iovw, void *old, void *new) {
2,373✔
112
        assert(iovw);
2,373✔
113

114
        FOREACH_ARRAY(i, iovw->iovec, iovw->count) {
24,813✔
115
                assert(i->iov_base >= old);
22,440✔
116
                i->iov_base = (uint8_t*) i->iov_base - (uint8_t*) old + (uint8_t*) new;
22,440✔
117
        }
118
}
2,373✔
119

120
size_t iovw_size(const struct iovec_wrapper *iovw) {
×
121
        if (!iovw)
×
122
                return 0;
123

124
        return iovec_total_size(iovw->iovec, iovw->count);
×
125
}
126

127
int iovw_append(struct iovec_wrapper *target, const struct iovec_wrapper *source) {
×
128
        size_t original_count;
×
129
        int r;
×
130

131
        assert(target);
×
132

133
        /* This duplicates the source and merges it into the target. */
134

135
        if (iovw_isempty(source))
×
136
                return 0;
137

138
        original_count = target->count;
×
139

140
        FOREACH_ARRAY(iovec, source->iovec, source->count) {
×
141
                void *dup;
×
142

143
                dup = memdup(iovec->iov_base, iovec->iov_len);
×
144
                if (!dup) {
×
145
                        r = -ENOMEM;
×
146
                        goto rollback;
×
147
                }
148

149
                r = iovw_consume(target, dup, iovec->iov_len);
×
150
                if (r < 0)
×
151
                        goto rollback;
×
152
        }
153

154
        return 0;
155

156
rollback:
×
157
        for (size_t i = original_count; i < target->count; i++)
×
158
                iovec_done(target->iovec + i);
×
159

160
        target->count = original_count;
×
161
        return r;
×
162
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc