Merge pull request #33493 from poettering/stub-refactor
sd-stub: clean-up codebase/refactoring
This commit is contained in:
+1
-25
@@ -6,6 +6,7 @@
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "iovec-util-fundamental.h"
|
||||
#include "macro.h"
|
||||
|
||||
extern const struct iovec iovec_nul_byte; /* Points to a single NUL byte */
|
||||
@@ -15,13 +16,6 @@ size_t iovec_total_size(const struct iovec *iovec, size_t n);
|
||||
|
||||
bool iovec_increment(struct iovec *iovec, size_t n, size_t k);
|
||||
|
||||
/* This accepts both const and non-const pointers */
|
||||
#define IOVEC_MAKE(base, len) \
|
||||
(struct iovec) { \
|
||||
.iov_base = (void*) (base), \
|
||||
.iov_len = (len), \
|
||||
}
|
||||
|
||||
static inline struct iovec* iovec_make_string(struct iovec *iovec, const char *s) {
|
||||
assert(iovec);
|
||||
/* We don't use strlen_ptr() here, because we don't want to include string-util.h for now */
|
||||
@@ -38,14 +32,6 @@ static inline struct iovec* iovec_make_string(struct iovec *iovec, const char *s
|
||||
.iov_len = STRLEN(s), \
|
||||
}
|
||||
|
||||
static inline void iovec_done(struct iovec *iovec) {
|
||||
/* A _cleanup_() helper that frees the iov_base in the iovec */
|
||||
assert(iovec);
|
||||
|
||||
iovec->iov_base = mfree(iovec->iov_base);
|
||||
iovec->iov_len = 0;
|
||||
}
|
||||
|
||||
static inline void iovec_done_erase(struct iovec *iovec) {
|
||||
assert(iovec);
|
||||
|
||||
@@ -53,16 +39,6 @@ static inline void iovec_done_erase(struct iovec *iovec) {
|
||||
iovec->iov_len = 0;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -211,16 +211,10 @@ static inline int __coverity_check_and_return__(int condition) {
|
||||
#define PTR_TO_UINT64(p) ((uint64_t) ((uintptr_t) (p)))
|
||||
#define UINT64_TO_PTR(u) ((void *) ((uintptr_t) (u)))
|
||||
|
||||
#define PTR_TO_SIZE(p) ((size_t) ((uintptr_t) (p)))
|
||||
#define SIZE_TO_PTR(u) ((void *) ((uintptr_t) (u)))
|
||||
|
||||
#define CHAR_TO_STR(x) ((char[2]) { x, 0 })
|
||||
|
||||
#define char_array_0(x) x[sizeof(x)-1] = 0;
|
||||
|
||||
#define sizeof_field(struct_type, member) sizeof(((struct_type *) 0)->member)
|
||||
#define endoffsetof_field(struct_type, member) (offsetof(struct_type, member) + sizeof_field(struct_type, member))
|
||||
|
||||
/* Maximum buffer size needed for formatting an unsigned integer type as hex, including space for '0x'
|
||||
* prefix and trailing NUL suffix. */
|
||||
#define HEXADECIMAL_STR_MAX(type) (2 + sizeof(type) * 2 + 1)
|
||||
@@ -266,18 +260,6 @@ static inline int __coverity_check_and_return__(int condition) {
|
||||
/* Pointers range from NULL to POINTER_MAX */
|
||||
#define POINTER_MAX ((void*) UINTPTR_MAX)
|
||||
|
||||
#define _FOREACH_ARRAY(i, array, num, m, end) \
|
||||
for (typeof(array[0]) *i = (array), *end = ({ \
|
||||
typeof(num) m = (num); \
|
||||
(i && m > 0) ? i + m : NULL; \
|
||||
}); end && i < end; i++)
|
||||
|
||||
#define FOREACH_ARRAY(i, array, num) \
|
||||
_FOREACH_ARRAY(i, array, num, UNIQ_T(m, UNIQ), UNIQ_T(end, UNIQ))
|
||||
|
||||
#define FOREACH_ELEMENT(i, array) \
|
||||
FOREACH_ARRAY(i, array, ELEMENTSOF(array))
|
||||
|
||||
#define _DEFINE_TRIVIAL_REF_FUNC(type, name, scope) \
|
||||
scope type *name##_ref(type *p) { \
|
||||
if (!p) \
|
||||
|
||||
Reference in New Issue
Block a user