macro: Reduce transitive includes
This commit is contained in:
@@ -137,6 +137,29 @@ static inline void *memdup_suffix0_multiply(const void *p, size_t need, size_t s
|
||||
return memdup_suffix0(p, size * need);
|
||||
}
|
||||
|
||||
static inline size_t GREEDY_ALLOC_ROUND_UP(size_t l) {
|
||||
size_t m;
|
||||
|
||||
/* Round up allocation sizes a bit to some reasonable, likely larger value. This is supposed to be
|
||||
* used for cases which are likely called in an allocation loop of some form, i.e. that repetitively
|
||||
* grow stuff, for example strv_extend() and suchlike.
|
||||
*
|
||||
* Note the difference to GREEDY_REALLOC() here, as this helper operates on a single size value only,
|
||||
* and rounds up to next multiple of 2, needing no further counter.
|
||||
*
|
||||
* Note the benefits of direct ALIGN_POWER2() usage: type-safety for size_t, sane handling for very
|
||||
* small (i.e. <= 2) and safe handling for very large (i.e. > SSIZE_MAX) values. */
|
||||
|
||||
if (l <= 2)
|
||||
return 2; /* Never allocate less than 2 of something. */
|
||||
|
||||
m = ALIGN_POWER2(l);
|
||||
if (m == 0) /* overflow? */
|
||||
return l;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
void* greedy_realloc(void **p, size_t need, size_t size);
|
||||
void* greedy_realloc0(void **p, size_t need, size_t size);
|
||||
void* greedy_realloc_append(void **p, size_t *n_p, const void *from, size_t n_from, size_t size);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <endian.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "arphrd-util.h"
|
||||
#include "assert-util.h"
|
||||
#include "macro.h"
|
||||
|
||||
static const struct arphrd_name* lookup_arphrd(register const char *str, register GPERF_LEN_TYPE len);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "assert-util.h"
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "capsule-util.h"
|
||||
#include "path-util.h"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "errno-list.h"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "chase.h"
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
#include "stdio-util.h"
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "assert-util.h"
|
||||
#include "macro.h"
|
||||
#include "path-util.h"
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "assert-util.h"
|
||||
#include "macro.h"
|
||||
#include "string.h"
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "assert-util.h"
|
||||
#include "errno-list.h"
|
||||
#include "macro.h"
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -42,6 +43,12 @@ static inline void _reset_errno_(int *saved_errno) {
|
||||
PROTECT_ERRNO; \
|
||||
errno = ABS(value)
|
||||
|
||||
#define return_with_errno(r, err) \
|
||||
do { \
|
||||
errno = ABS(err); \
|
||||
return r; \
|
||||
} while (false)
|
||||
|
||||
static inline int negative_errno(void) {
|
||||
/* This helper should be used to shut up gcc if you know 'errno' is
|
||||
* negative. Instead of "return -errno;", use "return negative_errno();"
|
||||
@@ -103,8 +110,6 @@ static inline int errno_or_else(int fallback) {
|
||||
return ERRNO_IS_NEG_##name(-ABS(r)); \
|
||||
}
|
||||
|
||||
assert_cc(INT_MAX <= INTMAX_MAX);
|
||||
|
||||
/* For send()/recv() or read()/write(). */
|
||||
static inline bool ERRNO_IS_NEG_TRANSIENT(intmax_t r) {
|
||||
return IN_SET(r,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
#include "hash-funcs.h"
|
||||
#include "path-util.h"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "assert-util.h"
|
||||
#include "ioprio-util.h"
|
||||
#include "parse-util.h"
|
||||
#include "string-table.h"
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "iovec-util.h"
|
||||
#include "iovec-wrapper.h"
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "assert-util.h"
|
||||
#include "label.h"
|
||||
#include "macro.h"
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <errno.h>
|
||||
#include <libintl.h>
|
||||
#include <locale.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "assert-util.h"
|
||||
#include "macro.h"
|
||||
|
||||
/* Some structures we reference but don't want to pull in headers for */
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/sysmacros.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "constants.h"
|
||||
#include "macro-fundamental.h"
|
||||
|
||||
@@ -32,15 +25,6 @@
|
||||
/* test harness */
|
||||
#define EXIT_TEST_SKIP 77
|
||||
|
||||
/* builtins */
|
||||
#if __SIZEOF_INT__ == 4
|
||||
#define BUILTIN_FFS_U32(x) __builtin_ffs(x);
|
||||
#elif __SIZEOF_LONG__ == 4
|
||||
#define BUILTIN_FFS_U32(x) __builtin_ffsl(x);
|
||||
#else
|
||||
#error "neither int nor long are four bytes long?!?"
|
||||
#endif
|
||||
|
||||
static inline uint64_t u64_multiply_safe(uint64_t a, uint64_t b) {
|
||||
if (_unlikely_(a != 0 && b > (UINT64_MAX / a)))
|
||||
return 0; /* overflow */
|
||||
@@ -66,29 +50,6 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
|
||||
return 1UL << (sizeof(u) * 8 - __builtin_clzl(u - 1UL));
|
||||
}
|
||||
|
||||
static inline size_t GREEDY_ALLOC_ROUND_UP(size_t l) {
|
||||
size_t m;
|
||||
|
||||
/* Round up allocation sizes a bit to some reasonable, likely larger value. This is supposed to be
|
||||
* used for cases which are likely called in an allocation loop of some form, i.e. that repetitively
|
||||
* grow stuff, for example strv_extend() and suchlike.
|
||||
*
|
||||
* Note the difference to GREEDY_REALLOC() here, as this helper operates on a single size value only,
|
||||
* and rounds up to next multiple of 2, needing no further counter.
|
||||
*
|
||||
* Note the benefits of direct ALIGN_POWER2() usage: type-safety for size_t, sane handling for very
|
||||
* small (i.e. <= 2) and safe handling for very large (i.e. > SSIZE_MAX) values. */
|
||||
|
||||
if (l <= 2)
|
||||
return 2; /* Never allocate less than 2 of something. */
|
||||
|
||||
m = ALIGN_POWER2(l);
|
||||
if (m == 0) /* overflow? */
|
||||
return l;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/*
|
||||
* container_of - cast a member of a structure out to the containing structure
|
||||
* @ptr: the pointer to the member.
|
||||
@@ -102,12 +63,6 @@ static inline size_t GREEDY_ALLOC_ROUND_UP(size_t l) {
|
||||
(type*)( (char *)UNIQ_T(A, uniq) - offsetof(type, member) ); \
|
||||
})
|
||||
|
||||
#define return_with_errno(r, err) \
|
||||
do { \
|
||||
errno = ABS(err); \
|
||||
return r; \
|
||||
} while (false)
|
||||
|
||||
#define PTR_TO_INT(p) ((int) ((intptr_t) (p)))
|
||||
#define INT_TO_PTR(u) ((void *) ((intptr_t) (u)))
|
||||
#define PTR_TO_UINT(p) ((unsigned) ((uintptr_t) (p)))
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <malloc.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "assert-util.h"
|
||||
#include "set.h"
|
||||
|
||||
#define NULSTR_FOREACH(i, l) \
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include <limits.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "assert-util.h"
|
||||
#include "macro.h"
|
||||
#include "ratelimit.h"
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "assert-util.h"
|
||||
#include "macro.h"
|
||||
|
||||
/* This is the same as glibc's internal __compar_d_fn_t type. glibc exports a public comparison_fn_t, for the
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "macro.h"
|
||||
#include "memory-util.h"
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "parse-util.h"
|
||||
#include "string-table.h"
|
||||
#include "string-util.h"
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "macro.h"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include <limits.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "sd-id128.h"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
Reference in New Issue
Block a user