basic + fundamental: Clean up includes

Split out of #37344.
This commit is contained in:
Daan De Meyer
2025-05-22 16:08:26 +02:00
parent e6e6131a2c
commit 0c15577abe
262 changed files with 628 additions and 1207 deletions

View File

@@ -1,11 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <string.h>
#include <sys/socket.h>
#include "af-list.h"
#include "macro.h"
#include "string-util.h"
static const struct af_name* lookup_af(register const char *str, register GPERF_LEN_TYPE len);

View File

@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include "macro.h"
#include "forward.h"
const char* af_to_name(int id) _const_;
int af_from_name(const char *name) _pure_;

View File

@@ -1,11 +1,8 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <malloc.h>
#include <stdint.h>
#include <string.h>
#include "alloc-util.h"
#include "macro.h"
void* memdup(const void *p, size_t l) {
void *ret;
@@ -131,3 +128,17 @@ void* greedy_realloc_append(
void *expand_to_usable(void *ptr, size_t newsize _unused_) {
return ptr;
}
size_t malloc_sizeof_safe(void **xp) {
if (_unlikely_(!xp || !*xp))
return 0;
size_t sz = malloc_usable_size(*xp);
*xp = expand_to_usable(*xp, sz);
/* GCC doesn't see the _returns_nonnull_ when built with ubsan, so yet another hint to make it doubly
* clear that expand_to_usable won't return NULL.
* See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79265 */
if (!*xp)
assert_not_reached();
return sz;
}

View File

@@ -1,14 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <alloca.h>
#include <malloc.h>
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
#include "assert-util.h"
#include "cleanup-util.h"
#include "macro.h"
#include "forward.h"
#include "memory-util.h"
#if HAS_FEATURE_MEMORY_SANITIZER
@@ -191,19 +186,7 @@ void* greedy_realloc_append(void **p, size_t *n_p, const void *from, size_t n_fr
* See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96503 */
void *expand_to_usable(void *p, size_t newsize) _alloc_(2) _returns_nonnull_ _noinline_;
static inline size_t malloc_sizeof_safe(void **xp) {
if (_unlikely_(!xp || !*xp))
return 0;
size_t sz = malloc_usable_size(*xp);
*xp = expand_to_usable(*xp, sz);
/* GCC doesn't see the _returns_nonnull_ when built with ubsan, so yet another hint to make it doubly
* clear that expand_to_usable won't return NULL.
* See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79265 */
if (!*xp)
assert_not_reached();
return sz;
}
size_t malloc_sizeof_safe(void **xp);
/* This returns the number of usable bytes in a malloc()ed region as per malloc_usable_size(), which may
* return a value larger than the size that was actually allocated. Access to that additional memory is

View File

@@ -1,9 +1,12 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <stdlib.h>
#include "ansi-color.h"
#include "log.h"
#include "process-util.h"
#include "string-table.h"
#include "string-util.h"
#include "strv.h"
#include "terminal-util.h"

View File

@@ -1,9 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <errno.h>
#include "macro.h"
#include "forward.h"
/* Limits the use of ANSI colors to a subset. */
typedef enum ColorMode {

View File

@@ -3,7 +3,6 @@
#include <sys/utsname.h>
#include "architecture.h"
#include "macro.h"
#include "string-table.h"
#include "string-util.h"

View File

@@ -1,10 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <endian.h>
#include <errno.h>
#include <endian.h> /* IWYU pragma: keep */
#include "macro.h"
#include "forward.h"
/* A cleaned up architecture definition. We don't want to get lost in
* processor features, models, generations or even ABIs. Hence we

View File

@@ -1,9 +1,8 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <sched.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/prctl.h>
#include <unistd.h>
#include "argv-util.h"
#include "capability-util.h"
@@ -19,6 +18,16 @@
int saved_argc = 0;
char **saved_argv = NULL;
void save_argc_argv(int argc, char **argv) {
/* Protect against CVE-2021-4034 style attacks */
assert_se(argc > 0);
assert_se(argv);
assert_se(argv[0]);
saved_argc = argc;
saved_argv = argv;
}
bool invoked_as(char *argv[], const char *token) {
if (!argv || isempty(argv[0]))
return false;

View File

@@ -1,23 +1,12 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <stdbool.h>
#include "assert-util.h"
#include "macro.h"
#include "forward.h"
extern int saved_argc;
extern char **saved_argv;
static inline void save_argc_argv(int argc, char **argv) {
/* Protect against CVE-2021-4034 style attacks */
assert_se(argc > 0);
assert_se(argv);
assert_se(argv[0]);
saved_argc = argc;
saved_argv = argv;
}
void save_argc_argv(int argc, char **argv);
bool invoked_as(char *argv[], const char *token);
bool invoked_by_systemd(void);

View File

@@ -1,14 +1,11 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <linux/if_arp.h>
#include <linux/if_infiniband.h>
#include <netinet/in.h>
#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);

View File

@@ -1,8 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <inttypes.h>
#include <stddef.h>
#include "forward.h"
const char* arphrd_to_name(int id);
int arphrd_from_name(const char *name);

View File

@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include "assert-util.h"
#include "errno-util.h"

View File

@@ -1,8 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include "assert-fundamental.h"
#include "macro.h"
#include "assert-fundamental.h" /* IWYU pragma: export */
/* Logging for various assertions */

View File

@@ -4,6 +4,7 @@
#include "audit-util.h"
#include "fileio.h"
#include "parse-util.h"
#include "pidref.h"
#include "process-util.h"
#include "stat-util.h"
#include "user-util.h"

View File

@@ -1,10 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "pidref.h"
#include "forward.h"
#define AUDIT_SESSION_INVALID UINT32_MAX

View File

@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include "macro.h"
#include "forward.h"
/* Bit index (0-based) to mask of specified type. Assertion failure if index is out of range. */
#define _INDEX_TO_MASK(type, i, uniq) \

View File

@@ -2,12 +2,12 @@
#include <linux/btrfs.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include "alloc-util.h"
#include "btrfs.h"
#include "errno-util.h"
#include "fd-util.h"
#include "fs-util.h"
#include "path-util.h"
#include "string-util.h"

View File

@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <fcntl.h>
#include "forward.h"
int btrfs_validate_subvolume_name(const char *name);

View File

@@ -1,17 +1,16 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <elf.h>
#include <fcntl.h>
#include <link.h>
#include <stdlib.h>
#include <sys/auxv.h>
#include "alloc-util.h"
#include "build-path.h"
#include "errno-list.h"
#include "errno-util.h"
#include "fd-util.h"
#include "macro.h"
#include "path-util.h"
#include "process-util.h"
#include "string-util.h"
#include "unistd.h"
static int get_runpath_from_dynamic(const ElfW(Dyn) *d, ElfW(Addr) bias, const char **ret) {

View File

@@ -7,9 +7,7 @@
#include "build.h"
#include "extract-word.h"
#include "log.h"
#include "macro.h"
#include "string-util.h"
#include "terminal-util.h"
#include "version.h"
const char* const systemd_features =

View File

@@ -1,6 +1,8 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include "forward.h"
extern const char* const systemd_features;
int version(void);

View File

@@ -5,7 +5,7 @@
#include "alloc-util.h"
#include "bus-label.h"
#include "hexdecoct.h"
#include "macro.h"
#include "string-util.h"
char* bus_label_escape(const char *s) {
char *r, *t;
@@ -48,6 +48,9 @@ char* bus_label_unescape_n(const char *f, size_t l) {
assert_return(f, NULL);
if (l == SIZE_MAX)
l = strlen(f);
/* Special case for the empty string */
if (l == 1 && *f == '_')
return strdup("");

View File

@@ -1,14 +1,11 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <stddef.h>
#include <stdlib.h>
#include "string-util.h"
#include "forward.h"
char* bus_label_escape(const char *s);
char* bus_label_unescape_n(const char *f, size_t l);
static inline char* bus_label_unescape(const char *f) {
return bus_label_unescape_n(f, strlen_ptr(f));
return bus_label_unescape_n(f, SIZE_MAX);
}

View File

@@ -1,7 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include "alloc-util.h"
#include "bitfield.h"
@@ -9,9 +8,7 @@
#include "capability-util.h"
#include "extract-word.h"
#include "log.h"
#include "macro.h"
#include "parse-util.h"
#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"

View File

@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <inttypes.h>
#include "forward.h"
/* Space for capability_to_string() in case we write out a numeric capability because we don't know the name
* for it. "0x3e" is the largest string we might output, in both sensese of the word "largest": two chars for

View File

@@ -1,12 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <linux/prctl.h>
#include <stdatomic.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/prctl.h>
#include <threads.h>
#include <unistd.h>
#include "alloc-util.h"
@@ -17,7 +14,6 @@
#include "fileio.h"
#include "log.h"
#include "logarithm.h"
#include "macro.h"
#include "parse-util.h"
#include "pidref.h"
#include "process-util.h"

View File

@@ -1,13 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <sys/capability.h>
#include <sys/types.h>
#include <sys/capability.h> /* IWYU pragma: export */
#include "macro.h"
#include "pidref.h"
#include "forward.h"
/* Special marker used when storing a capabilities mask as "unset". This would need to be updated as soon as
* Linux learns more than 63 caps. */

View File

@@ -1,10 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include "alloc-util.h"
#include "capsule-util.h"
#include "path-util.h"
#include "string-util.h"
#include "user-util.h"
int capsule_name_is_valid(const char *name) {

View File

@@ -1,4 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include "forward.h"
int capsule_name_is_valid(const char *name);

View File

@@ -1,12 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <limits.h>
#include <signal.h>
#include <stddef.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/xattr.h>
#include <threads.h>
#include <unistd.h>
@@ -14,7 +9,6 @@
#include "alloc-util.h"
#include "capsule-util.h"
#include "cgroup-util.h"
#include "constants.h"
#include "dirent-util.h"
#include "errno-util.h"
#include "extract-word.h"
@@ -24,17 +18,15 @@
#include "fs-util.h"
#include "log.h"
#include "login-util.h"
#include "macro.h"
#include "missing_fs.h"
#include "missing_magic.h"
#include "mkdir.h"
#include "parse-util.h"
#include "path-util.h"
#include "pidref.h"
#include "process-util.h"
#include "set.h"
#include "special.h"
#include "stat-util.h"
#include "stdio-util.h"
#include "string-table.h"
#include "string-util.h"
#include "strv.h"
@@ -42,6 +34,20 @@
#include "user-util.h"
#include "xattr-util.h"
/* The structure to pass to name_to_handle_at() on cgroupfs2 */
typedef union {
struct file_handle file_handle;
uint8_t space[offsetof(struct file_handle, f_handle) + sizeof(uint64_t)];
} cg_file_handle;
#define CG_FILE_HANDLE_INIT \
(cg_file_handle) { \
.file_handle.handle_bytes = sizeof(uint64_t), \
.file_handle.handle_type = FILEID_KERNFS, \
}
#define CG_FILE_HANDLE_CGROUPID(fh) (*CAST_ALIGN_PTR(uint64_t, (fh).file_handle.f_handle))
int cg_path_open(const char *controller, const char *path) {
_cleanup_free_ char *fs = NULL;
int r;

View File

@@ -1,18 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/statfs.h>
#include <sys/types.h>
#include "constants.h"
#include "pidref.h"
#include "set.h"
#include "forward.h"
#define SYSTEMD_CGROUP_CONTROLLER_LEGACY "name=systemd"
#define SYSTEMD_CGROUP_CONTROLLER_HYBRID "name=unified"
@@ -319,17 +308,3 @@ typedef enum ManagedOOMPreference {
const char* managed_oom_preference_to_string(ManagedOOMPreference a) _const_;
ManagedOOMPreference managed_oom_preference_from_string(const char *s) _pure_;
/* The structure to pass to name_to_handle_at() on cgroupfs2 */
typedef union {
struct file_handle file_handle;
uint8_t space[offsetof(struct file_handle, f_handle) + sizeof(uint64_t)];
} cg_file_handle;
#define CG_FILE_HANDLE_INIT \
(cg_file_handle) { \
.file_handle.handle_bytes = sizeof(uint64_t), \
.file_handle.handle_type = FILEID_KERNFS, \
}
#define CG_FILE_HANDLE_CGROUPID(fh) (*CAST_ALIGN_PTR(uint64_t, (fh).file_handle.f_handle))

View File

@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <linux/magic.h>
#include <unistd.h>
#include "alloc-util.h"
#include "chase.h"
@@ -11,6 +12,7 @@
#include "glyph-util.h"
#include "log.h"
#include "path-util.h"
#include "stat-util.h"
#include "string-util.h"
#include "strv.h"
#include "user-util.h"

View File

@@ -1,10 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <dirent.h>
#include <stdio.h>
#include "stat-util.h"
#include "forward.h"
typedef enum ChaseFlags {
CHASE_PREFIX_ROOT = 1 << 0, /* The specified path will be prefixed by the specified root before beginning the iteration */

View File

@@ -1,6 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
@@ -11,7 +10,6 @@
#include "fd-util.h"
#include "fs-util.h"
#include "log.h"
#include "macro.h"
#include "string-util.h"
int chattr_full(

View File

@@ -1,10 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <fcntl.h>
#include <stdbool.h>
#include <stddef.h>
#include "forward.h"
#include "missing_fs.h"
/* The chattr() flags to apply when creating a new file *before* writing to it. In particular, flags such as

View File

@@ -1,11 +1,8 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <inttypes.h>
#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#if HAVE_LZ4
@@ -26,12 +23,10 @@
#include "alloc-util.h"
#include "bitfield.h"
#include "compress.h"
#include "fd-util.h"
#include "dlfcn-util.h"
#include "fileio.h"
#include "io-util.h"
#include "log.h"
#include "macro.h"
#include "sparse-endian.h"
#include "string-table.h"
#include "string-util.h"
#include "unaligned.h"

View File

@@ -1,12 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
#include "dlfcn-util.h"
#include "forward.h"
typedef enum Compression {
COMPRESSION_NONE,

View File

@@ -1,14 +1,11 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "alloc-util.h"
#include "chase.h"
#include "conf-files.h"
#include "constants.h"
#include "dirent-util.h"
#include "errno-util.h"
#include "fd-util.h"
@@ -16,14 +13,12 @@
#include "glyph-util.h"
#include "hashmap.h"
#include "log.h"
#include "macro.h"
#include "nulstr-util.h"
#include "path-util.h"
#include "set.h"
#include "stat-util.h"
#include "string-util.h"
#include "strv.h"
#include "terminal-util.h"
static int files_add(
DIR *dir,

View File

@@ -1,9 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <stdbool.h>
#include "macro.h"
#include "forward.h"
enum {
CONF_FILES_EXECUTABLE = 1 << 0,

View File

@@ -3,13 +3,10 @@
#if defined(__i386__) || defined(__x86_64__)
#include <cpuid.h>
#endif
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <threads.h>
#include <unistd.h>
#include "alloc-util.h"
#include "confidential-virt.h"
#include "confidential-virt-fundamental.h"
#include "errno-util.h"

View File

@@ -1,11 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <errno.h>
#include <stdbool.h>
#include "errno-list.h"
#include "macro.h"
#include "forward.h"
typedef enum ConfidentialVirtualization {
CONFIDENTIAL_VIRTUALIZATION_NONE = 0,

View File

@@ -9,6 +9,7 @@
#include "devnum-util.h"
#include "parse-util.h"
#include "path-util.h"
#include "stdio-util.h"
#include "string-util.h"
int parse_devnum(const char *s, dev_t *ret) {
@@ -135,3 +136,7 @@ int device_path_parse_major_minor(const char *path, mode_t *ret_mode, dev_t *ret
return 0;
}
char* format_devnum(dev_t d, char buf[static DEVNUM_STR_MAX]) {
return ASSERT_PTR(snprintf_ok(buf, DEVNUM_STR_MAX, DEVNUM_FORMAT_STR, DEVNUM_FORMAT_VAL(d)));
}

View File

@@ -1,12 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <inttypes.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/sysmacros.h>
#include "stdio-util.h"
#include "forward.h"
int parse_devnum(const char *s, dev_t *ret);
@@ -49,9 +46,7 @@ static inline bool devnum_set_and_equal(dev_t a, dev_t b) {
#define DEVNUM_FORMAT_STR "%u:%u"
#define DEVNUM_FORMAT_VAL(d) major(d), minor(d)
static inline char *format_devnum(dev_t d, char buf[static DEVNUM_STR_MAX]) {
return ASSERT_PTR(snprintf_ok(buf, DEVNUM_STR_MAX, DEVNUM_FORMAT_STR, DEVNUM_FORMAT_VAL(d)));
}
char *format_devnum(dev_t d, char buf[static DEVNUM_STR_MAX]);
#define FORMAT_DEVNUM(d) format_devnum((d), (char[DEVNUM_STR_MAX]) {})

View File

@@ -5,7 +5,6 @@
#include "dirent-util.h"
#include "path-util.h"
#include "stat-util.h"
#include "string-util.h"
int dirent_ensure_type(int dir_fd, struct dirent *de) {

View File

@@ -1,12 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <dirent.h>
#include <errno.h>
#include <stdbool.h>
#include <dirent.h> /* IWYU pragma: export */
#include "assert-util.h"
#include "macro.h"
#include "forward.h"
#include "path-util.h"
bool dirent_is_file(const struct dirent *de) _pure_;

View File

@@ -3,6 +3,14 @@
#include "dlfcn-util.h"
#include "log.h"
void* safe_dlclose(void *dl) {
if (!dl)
return NULL;
assert_se(dlclose(dl) == 0);
return NULL;
}
static int dlsym_many_or_warnv(void *dl, int log_level, va_list ap) {
void (**fn)(void);

View File

@@ -1,18 +1,11 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <dlfcn.h>
#include <dlfcn.h> /* IWYU pragma: export */
#include "assert-util.h"
#include "macro.h"
#include "forward.h"
static inline void* safe_dlclose(void *dl) {
if (!dl)
return NULL;
assert_se(dlclose(dl) == 0);
return NULL;
}
void* safe_dlclose(void *dl);
static inline void dlclosep(void **dlp) {
safe_dlclose(*dlp);

View File

@@ -1,6 +1,8 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include "forward.h"
/* Length of a single label, with all escaping removed, excluding any trailing dot or NUL byte */
#define DNS_LABEL_MAX 63

View File

@@ -1,26 +1,19 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#include "sd-id128.h"
#include "alloc-util.h"
#include "chattr-util.h"
#include "efivars.h"
#include "fd-util.h"
#include "fileio.h"
#include "io-util.h"
#include "log.h"
#include "macro.h"
#include "memory-util.h"
#include "missing_fs.h"
#include "stdio-util.h"
#include "strv.h"
#include "string-util.h"
#include "time-util.h"
#include "utf8.h"
#include "virt.h"
@@ -389,3 +382,7 @@ SecureBootMode efi_get_secure_boot_mode(void) {
return (cache = decode_secure_boot_mode(secure, audit > 0, deployed > 0, setup > 0));
}
#endif
char *efi_tilt_backslashes(char *s) {
return string_replace_char(s, '\\', '/');
}

View File

@@ -1,18 +1,11 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#if !ENABLE_EFI
# include <errno.h>
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "forward.h"
#include "sd-id128.h"
#include "efivars-fundamental.h"
#include "string-util.h"
#include "time-util.h"
#include "efivars-fundamental.h" /* IWYU pragma: export */
#define EFI_VENDOR_LOADER SD_ID128_MAKE(4a,67,b0,82,0a,4c,41,cf,b6,c7,44,0b,29,bb,8c,4f)
#define EFI_VENDOR_LOADER_STR SD_ID128_MAKE_UUID_STR(4a,67,b0,82,0a,4c,41,cf,b6,c7,44,0b,29,bb,8c,4f)
@@ -88,6 +81,4 @@ static inline SecureBootMode efi_get_secure_boot_mode(void) {
}
#endif
static inline char *efi_tilt_backslashes(char *s) {
return string_replace_char(s, '\\', '/');
}
char *efi_tilt_backslashes(char *s);

View File

@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <unistd.h>
#include "alloc-util.h"
#include "env-file.h"
#include "env-util.h"

View File

@@ -1,11 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include "macro.h"
#include "forward.h"
int parse_env_filev(FILE *f, const char *fname, va_list ap);
int parse_env_file_fdv(int fd, const char *fname, va_list ap);

View File

@@ -1,22 +1,17 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include "alloc-util.h"
#include "env-util.h"
#include "errno-util.h"
#include "escape.h"
#include "extract-word.h"
#include "format-util.h"
#include "log.h"
#include "macro.h"
#include "parse-util.h"
#include "path-util.h"
#include "process-util.h"
#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
#include "syslog-util.h"
@@ -27,6 +22,12 @@
DIGITS LETTERS \
"_"
size_t sc_arg_max(void) {
long l = sysconf(_SC_ARG_MAX);
assert(l > 0);
return (size_t) l;
}
static bool env_name_is_valid_n(const char *e, size_t n) {
if (n == SIZE_MAX)

View File

@@ -1,20 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
#include "forward.h"
#include "assert-util.h"
#include "macro.h"
#include "string.h"
static inline size_t sc_arg_max(void) {
long l = sysconf(_SC_ARG_MAX);
assert(l > 0);
return (size_t) l;
}
size_t sc_arg_max(void);
bool env_name_is_valid(const char *e);
bool env_value_is_valid(const char *e);

View File

@@ -1,18 +1,22 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <string.h>
#include "assert-util.h"
#include "errno-list.h"
#include "macro.h"
static const struct errno_name* lookup_errno(register const char *str,
register GPERF_LEN_TYPE len);
#include "errno-from-name.inc"
#if !HAVE_STRERRORNAME_NP
#if HAVE_STRERRORNAME_NP
const char* errno_to_name(int id) {
if (id == 0) /* To stay in line with our own impl */
return NULL;
return strerrorname_np(ABS(id));
}
#else
#include "errno-to-name.inc"
const char* errno_to_name(int id) {

View File

@@ -1,30 +1,11 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <errno.h>
#include <stdbool.h>
#include <string.h>
#include "forward.h"
#include "macro.h"
/*
* MAX_ERRNO is defined as 4095 in linux/err.h
* We use the same value here.
*/
#define ERRNO_MAX 4095
#if HAVE_STRERRORNAME_NP
static inline const char* errno_to_name(int id) {
if (id == 0) /* To stay in line with our own impl */
return NULL;
return strerrorname_np(ABS(id));
}
#else
const char* errno_to_name(int id);
#endif
int errno_from_name(const char *name);
int errno_from_name(const char *name) _const_;
static inline bool errno_is_valid(int n) {
return n > 0 && n <= ERRNO_MAX;

View File

@@ -1,15 +1,12 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <errno.h>
#include <inttypes.h>
#include <string.h>
#include "assert-util.h"
#include "macro.h"
#include "forward.h"
/* strerror(3) says that glibc uses a maximum length of 1024 bytes. */
#define ERRNO_BUF_LEN 1024
#define ERRNO_BUF_LEN 1024
/* Note: the lifetime of the compound literal is the immediately surrounding block,
* see C11 §6.5.2.5, and
@@ -55,6 +52,7 @@ static inline int negative_errno(void) {
* It will suppress bogus gcc warnings in case it assumes 'errno' might
* be 0 and thus the caller's error-handling might not be triggered. */
assert_return(errno > 0, -EINVAL);
return -errno;
}

View File

@@ -1,13 +1,12 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "alloc-util.h"
#include "escape.h"
#include "hexdecoct.h"
#include "macro.h"
#include "string-util.h"
#include "strv.h"
#include "utf8.h"
@@ -300,6 +299,9 @@ ssize_t cunescape_length_with_prefix(const char *s, size_t length, const char *p
/* Undoes C style string escaping, and optionally prefixes it. */
if (length == SIZE_MAX)
length = strlen(s);
pl = strlen_ptr(prefix);
ans = new(char, pl+length+1);

View File

@@ -1,13 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <inttypes.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#include <uchar.h>
#include "string-util.h"
#include "forward.h"
/* What characters are special in the shell? */
/* must be escaped outside and inside double-quotes */
@@ -53,7 +47,7 @@ static inline ssize_t cunescape_length(const char *s, size_t length, UnescapeFla
return cunescape_length_with_prefix(s, length, NULL, flags, ret);
}
static inline ssize_t cunescape(const char *s, UnescapeFlags flags, char **ret) {
return cunescape_length(s, strlen(s), flags, ret);
return cunescape_length(s, SIZE_MAX, flags, ret);
}
typedef enum XEscapeFlags {

View File

@@ -1,15 +1,14 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <inttypes.h>
#include <net/ethernet.h>
#include <stdio.h>
#include <sys/types.h>
#include "ether-addr-util.h"
#include "hash-funcs.h"
#include "hexdecoct.h"
#include "log.h"
#include "macro.h"
#include "in-addr-util.h"
#include "memory-util.h"
#include "siphash24.h"
#include "string-util.h"
char* hw_addr_to_string_full(
@@ -64,6 +63,11 @@ void hw_addr_hash_func(const struct hw_addr_data *p, struct siphash *state) {
siphash24_compress_safe(p->bytes, p->length, state);
}
bool hw_addr_is_null(const struct hw_addr_data *addr) {
assert(addr);
return addr->length == 0 || memeqzero(addr->bytes, addr->length);
}
DEFINE_HASH_OPS(hw_addr_hash_ops, struct hw_addr_data, hw_addr_hash_func, hw_addr_compare);
DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(hw_addr_hash_ops_free, struct hw_addr_data, hw_addr_hash_func, hw_addr_compare, free);
@@ -94,6 +98,11 @@ static void ether_addr_hash_func(const struct ether_addr *p, struct siphash *sta
siphash24_compress_typesafe(*p, state);
}
bool ether_addr_is_broadcast(const struct ether_addr *addr) {
assert(addr);
return memeqbyte(0xff, addr->ether_addr_octet, ETH_ALEN);
}
DEFINE_HASH_OPS(ether_addr_hash_ops, struct ether_addr, ether_addr_hash_func, ether_addr_compare);
DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(ether_addr_hash_ops_free, struct ether_addr, ether_addr_hash_func, ether_addr_compare, free);

View File

@@ -2,13 +2,10 @@
#pragma once
#include <linux/if_infiniband.h>
#include <netinet/in.h>
#include <net/ethernet.h>
#include <stdbool.h>
#include "hash-funcs.h"
#include "in-addr-util.h"
#include "macro.h"
#include "memory-util.h"
#include "forward.h"
/* This is MAX_ADDR_LEN as defined in linux/netdevice.h, but net/if_arp.h
* defines a macro of the same name with a much lower size. */
@@ -59,10 +56,7 @@ int hw_addr_compare(const struct hw_addr_data *a, const struct hw_addr_data *b);
static inline bool hw_addr_equal(const struct hw_addr_data *a, const struct hw_addr_data *b) {
return hw_addr_compare(a, b) == 0;
}
static inline bool hw_addr_is_null(const struct hw_addr_data *addr) {
assert(addr);
return addr->length == 0 || memeqzero(addr->bytes, addr->length);
}
bool hw_addr_is_null(const struct hw_addr_data *addr) _pure_;
extern const struct hash_ops hw_addr_hash_ops;
extern const struct hash_ops hw_addr_hash_ops_free;
@@ -86,10 +80,7 @@ static inline bool ether_addr_is_null(const struct ether_addr *addr) {
return ether_addr_equal(addr, &ETHER_ADDR_NULL);
}
static inline bool ether_addr_is_broadcast(const struct ether_addr *addr) {
assert(addr);
return memeqbyte(0xff, addr->ether_addr_octet, ETH_ALEN);
}
bool ether_addr_is_broadcast(const struct ether_addr *addr) _pure_;
static inline bool ether_addr_is_multicast(const struct ether_addr *addr) {
assert(addr);

View File

@@ -1,20 +1,10 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <syslog.h>
#include "alloc-util.h"
#include "escape.h"
#include "extract-word.h"
#include "log.h"
#include "macro.h"
#include "string-util.h"
#include "strv.h"
#include "utf8.h"
int extract_first_word(const char **p, char **ret, const char *separators, ExtractFlags flags) {

View File

@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include "macro.h"
#include "forward.h"
typedef enum ExtractFlags {
EXTRACT_RELAX = 1 << 0, /* Allow unbalanced quote and eat up trailing backslash. */

View File

@@ -1,9 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <fcntl.h>
#include <linux/kcmp.h>
#include <linux/magic.h>
#include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/stat.h>
@@ -11,12 +9,12 @@
#include "alloc-util.h"
#include "dirent-util.h"
#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "format-util.h"
#include "fs-util.h"
#include "io-util.h"
#include "log.h"
#include "macro.h"
#include "missing_fcntl.h"
#include "missing_fs.h"
#include "missing_syscall.h"
@@ -28,6 +26,7 @@
#include "sort-util.h"
#include "stat-util.h"
#include "stdio-util.h"
#include "string-util.h"
/* The maximum number of iterations in the loop to close descriptors in the fallback case
* when /proc/self/fd/ is inaccessible. */
@@ -1131,6 +1130,13 @@ int fds_are_same_mount(int fd1, int fd2) {
return statx_mount_same(&sx1, &sx2);
}
char* format_proc_fd_path(char buf[static PROC_FD_PATH_MAX], int fd) {
assert(buf);
assert(fd >= 0);
assert_se(snprintf_ok(buf, PROC_FD_PATH_MAX, "/proc/self/fd/%i", fd));
return buf;
}
const char* accmode_to_string(int flags) {
switch (flags & O_ACCMODE_STRICT) {
case O_RDONLY:

View File

@@ -2,16 +2,10 @@
#pragma once
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <sys/socket.h>
#include "macro.h"
#include "memory-util.h"
#include "forward.h"
#include "missing_fcntl.h"
#include "stdio-util.h"
/* maximum length of fdname */
#define FDNAME_MAX 255
@@ -42,6 +36,10 @@ void close_many_and_free(int *fds, size_t n_fds);
int fclose_nointr(FILE *f);
FILE* safe_fclose(FILE *f);
DIR* safe_closedir(DIR *f);
static inline void* close_fd_ptr(void *p) {
safe_close(PTR_TO_FD(p));
return NULL;
}
static inline void closep(int *fd) {
safe_close(*fd);
@@ -55,11 +53,6 @@ static inline void fclosep(FILE **f) {
safe_fclose(*f);
}
static inline void* close_fd_ptr(void *p) {
safe_close(PTR_TO_FD(p));
return NULL;
}
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(FILE*, pclose, NULL);
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(DIR*, closedir, NULL);
@@ -144,12 +137,7 @@ int fds_are_same_mount(int fd1, int fd2);
#define PROC_FD_PATH_MAX \
(STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int))
static inline char* format_proc_fd_path(char buf[static PROC_FD_PATH_MAX], int fd) {
assert(buf);
assert(fd >= 0);
assert_se(snprintf_ok(buf, PROC_FD_PATH_MAX, "/proc/self/fd/%i", fd));
return buf;
}
char* format_proc_fd_path(char buf[static PROC_FD_PATH_MAX], int fd);
#define FORMAT_PROC_FD_PATH(fd) \
format_proc_fd_path((char[PROC_FD_PATH_MAX]) {}, (fd))

View File

@@ -1,19 +1,13 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio_ext.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "alloc-util.h"
#include "chase.h"
#include "errno-util.h"
#include "extract-word.h"
#include "fd-util.h"
#include "fileio.h"
@@ -21,17 +15,18 @@
#include "hexdecoct.h"
#include "label.h"
#include "log.h"
#include "macro.h"
#include "mkdir.h"
#include "nulstr-util.h"
#include "parse-util.h"
#include "path-util.h"
#include "socket-util.h"
#include "stat-util.h"
#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
#include "sync-util.h"
#include "terminal-util.h"
#include "time-util.h"
#include "tmpfile-util.h"
/* The maximum size of the file we'll read in one go in read_full_file() (64M). */

View File

@@ -1,16 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <dirent.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "macro.h"
#include "time-util.h"
#include "forward.h"
#define LONG_LINE_MAX (1U*1024U*1024U)

View File

@@ -1,7 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "filesystems-gperf.h"
#include "nulstr-util.h"
#include "stat-util.h"
#include "string-util.h"
const char* fs_type_to_string(statfs_f_type_t magic) {

View File

@@ -1,9 +1,8 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include "nulstr-util.h"
#include "forward.h"
#include "stat-util.h"
#include "string-util.h"
#define FILESYSTEM_MAGIC_MAX 10

View File

@@ -1,7 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "format-ifname.h"
#include "log.h"
#include "stdio-util.h"
#include "string-util.h"

View File

@@ -1,9 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "format-util.h"
#include "memory-util.h"
#include "stdio-util.h"
#include "strxcpyx.h"
char* format_bytes_full(char *buf, size_t l, uint64_t t, FormatBytesFlag flag) {
typedef struct {

View File

@@ -1,11 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <inttypes.h>
#include <stdbool.h>
#include "cgroup-util.h"
#include "macro.h"
#include "forward.h"
#include "stdio-util.h"
assert_cc(sizeof(pid_t) == sizeof(int32_t));
#define PID_PRI PRIi32

View File

@@ -85,6 +85,7 @@ typedef enum CGroupFlags CGroupFlags;
typedef enum CGroupMask CGroupMask;
typedef enum ChaseFlags ChaseFlags;
typedef enum ExtractFlags ExtractFlags;
typedef enum Glyph Glyph;
typedef enum ImageClass ImageClass;
typedef enum JobMode JobMode;
typedef enum RuntimeScope RuntimeScope;

View File

@@ -1,9 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <linux/falloc.h>
#include <linux/magic.h>
#include <stddef.h>
#include <stdlib.h>
#include <sys/file.h>
#include <unistd.h>
@@ -14,30 +11,24 @@
#include "dirent-util.h"
#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
#include "hostname-util.h"
#include "label.h"
#include "lock-util.h"
#include "log.h"
#include "macro.h"
#include "missing_fcntl.h"
#include "missing_fs.h"
#include "missing_syscall.h"
#include "mkdir.h"
#include "parse-util.h"
#include "path-util.h"
#include "process-util.h"
#include "random-util.h"
#include "ratelimit.h"
#include "stat-util.h"
#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
#include "time-util.h"
#include "tmpfile-util.h"
#include "umask-util.h"
#include "user-util.h"
int rmdir_parents(const char *path, const char *stop) {
char *p;
@@ -695,6 +686,16 @@ char *rmdir_and_free(char *p) {
return mfree(p);
}
char* unlink_and_free(char *p) {
PROTECT_ERRNO;
if (!p)
return NULL;
(void) unlink(p);
return mfree(p);
}
int access_fd(int fd, int mode) {
assert(fd >= 0);

View File

@@ -1,20 +1,8 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <dirent.h>
#include <fcntl.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "forward.h"
#include "lock-util.h"
#include "memory-util.h"
#include "time-util.h"
#define MODE_INVALID ((mode_t) -1)
/* The following macros add 1 when converting things, since 0 is a valid mode, while the pointer
* NULL is special */
@@ -86,13 +74,7 @@ int unlink_or_warn(const char *filename);
char *rmdir_and_free(char *p);
DEFINE_TRIVIAL_CLEANUP_FUNC(char*, rmdir_and_free);
static inline char* unlink_and_free(char *p) {
if (!p)
return NULL;
(void) unlink(p);
return mfree(p);
}
char* unlink_and_free(char *p);
DEFINE_TRIVIAL_CLEANUP_FUNC(char*, unlink_and_free);
int access_fd(int fd, int mode);

View File

@@ -2,9 +2,9 @@
#if HAVE_GCRYPT
#include <sys/syslog.h>
#include "gcrypt-util.h"
#include "hexdecoct.h"
#include "log.h"
static void *gcrypt_dl = NULL;

View File

@@ -2,17 +2,12 @@
#pragma once
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include "memory-util.h"
#include "forward.h"
#if HAVE_GCRYPT
#include <gcrypt.h>
#include <gcrypt.h> /* IWYU pragma: export */
#include "dlfcn-util.h"
#include "macro.h"
extern DLSYM_PROTOTYPE(gcry_md_close);
extern DLSYM_PROTOTYPE(gcry_md_copy);

View File

@@ -1,16 +1,13 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "dirent-util.h"
#include "errno-util.h"
#include "glob-util.h"
#include "log.h"
#include "macro.h"
#include "path-util.h"
#include "string-util.h"
#include "strv.h"
static void closedir_wrapper(void* v) {
@@ -104,3 +101,8 @@ int glob_non_glob_prefix(const char *path, char **ret) {
*ret = ans;
return 0;
}
bool string_is_glob(const char *p) {
/* Check if a string contains any glob patterns. */
return !!strpbrk(p, GLOB_CHARS);
}

View File

@@ -1,11 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <glob.h>
#include <stdbool.h>
#include <glob.h> /* IWYU pragma: export */
#include "macro.h"
#include "string-util.h"
#include "forward.h"
/* Note: this function modifies pglob to set various functions. */
int safe_glob(const char *path, int flags, glob_t *pglob);
@@ -19,7 +17,4 @@ int glob_non_glob_prefix(const char *path, char **ret);
#define _cleanup_globfree_ _cleanup_(globfree)
_pure_ static inline bool string_is_glob(const char *p) {
/* Check if a string contains any glob patterns. */
return !!strpbrk(p, GLOB_CHARS);
}
bool string_is_glob(const char *p) _pure_;

View File

@@ -1,10 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <errno.h>
#include <stdbool.h>
#include "macro.h"
#include "forward.h"
typedef enum Glyph {
GLYPH_SPACE,

View File

@@ -5,8 +5,9 @@
* Copyright © 2000, 2005 Red Hat, Inc.
*/
#include <stdlib.h>
#include "gunicode.h"
#include "macro.h"
#define unichar uint32_t

View File

@@ -6,9 +6,7 @@
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include "forward.h"
char *utf8_prev_char (const char *p);

View File

@@ -1,10 +1,12 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <stdlib.h>
#include <string.h>
#include <sys/sysmacros.h>
#include "hash-funcs.h"
#include "path-util.h"
#include "siphash24.h"
#include "strv.h"
void string_hash_func(const char *p, struct siphash *state) {

View File

@@ -1,9 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include "alloc-util.h"
#include "macro.h"
#include "siphash24.h"
#include "forward.h"
typedef void (*hash_func_t)(const void *p, struct siphash *state);
typedef int (*compare_func_t)(const void *a, const void *b);

View File

@@ -1,23 +1,18 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <fnmatch.h>
#include <pthread.h>
#include <stdint.h>
#include <stdlib.h>
#if HAVE_VALGRIND_VALGRIND_H
# include <valgrind/valgrind.h>
#endif
#include "alloc-util.h"
#include "fileio.h"
#include "extract-word.h"
#include "hashmap.h"
#include "log.h"
#include "logarithm.h"
#include "macro.h"
#include "memory-util.h"
#include "mempool.h"
#include "missing_syscall.h"
#include "process-util.h"
#include "random-util.h"
#include "set.h"

View File

@@ -1,13 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include "forward.h"
#include "hash-funcs.h"
#include "iterator.h"
#include "macro.h"
/*
* A hash table implementation. As a minor optimization a NULL hashmap object
@@ -22,7 +18,6 @@
#define HASH_KEY_SIZE 16
typedef void* (*hashmap_destroy_t)(void *p);
/* The base type for all hashmap and set types. Many functions in the implementation take (HashmapBase*)
* parameters and are run-time polymorphic, though the API is not meant to be polymorphic (do not call

View File

@@ -1,14 +1,10 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include "alloc-util.h"
#include "hexdecoct.h"
#include "macro.h"
#include "memory-util.h"
#include "string-util.h"

View File

@@ -1,12 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/types.h>
#include "macro.h"
#include "forward.h"
char octchar(int x) _const_;
int unoctchar(char c) _const_;

View File

@@ -1,6 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <assert.h>
#include <string.h>
#include "hmac.h"

View File

@@ -1,9 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <stdint.h>
#include <stdlib.h>
#include "forward.h"
#include "sha256.h"
/* Unoptimized implementation based on FIPS 198. 'res' has to be allocated by

View File

@@ -1,11 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/utsname.h>
#include <unistd.h>
#include "alloc-util.h"
#include "env-file.h"

View File

@@ -1,10 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <stdbool.h>
#include <stdio.h>
#include "macro.h"
#include "forward.h"
#include "strv.h"
char* get_default_hostname_raw(void);

View File

@@ -2,23 +2,19 @@
#include <arpa/inet.h>
#include <endian.h>
#include <errno.h>
#include <net/if.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "alloc-util.h"
#include "errno-util.h"
#include "hash-funcs.h"
#include "in-addr-util.h"
#include "logarithm.h"
#include "macro.h"
#include "memory-util.h"
#include "parse-util.h"
#include "random-util.h"
#include "siphash24.h"
#include "stdio-util.h"
#include "string-util.h"
#include "strxcpyx.h"
bool in4_addr_is_null(const struct in_addr *a) {
assert(a);
@@ -493,6 +489,18 @@ int in_addr_to_string(int family, const union in_addr_union *u, char **ret) {
return 0;
}
const char* typesafe_inet_ntop(int family, const union in_addr_union *a, char *buf, size_t len) {
return inet_ntop(family, a, buf, len);
}
const char* typesafe_inet_ntop4(const struct in_addr *a, char *buf, size_t len) {
return inet_ntop(AF_INET, a, buf, len);
}
const char* typesafe_inet_ntop6(const struct in6_addr *a, char *buf, size_t len) {
return inet_ntop(AF_INET6, a, buf, len);
}
int in_addr_prefix_to_string(
int family,
const union in_addr_union *u,

View File

@@ -1,13 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stddef.h>
#include <sys/socket.h>
#include "hash-funcs.h"
#include "macro.h"
#include "forward.h"
union in_addr_union {
struct in_addr in;
@@ -92,15 +88,9 @@ static inline int in6_addr_to_string(const struct in6_addr *u, char **ret) {
return in_addr_to_string(AF_INET6, (const union in_addr_union*) u, ret);
}
static inline const char* typesafe_inet_ntop(int family, const union in_addr_union *a, char *buf, size_t len) {
return inet_ntop(family, a, buf, len);
}
static inline const char* typesafe_inet_ntop4(const struct in_addr *a, char *buf, size_t len) {
return inet_ntop(AF_INET, a, buf, len);
}
static inline const char* typesafe_inet_ntop6(const struct in6_addr *a, char *buf, size_t len) {
return inet_ntop(AF_INET6, a, buf, len);
}
const char* typesafe_inet_ntop(int family, const union in_addr_union *a, char *buf, size_t len);
const char* typesafe_inet_ntop4(const struct in_addr *a, char *buf, size_t len);
const char* typesafe_inet_ntop6(const struct in6_addr *a, char *buf, size_t len);
/* Note: the lifetime of the compound literal is the immediately surrounding block,
* see C11 §6.5.2.5, and
@@ -187,8 +177,14 @@ static inline int in_addr_prefix_from_string_auto(const char *p, int *ret_family
}
static inline size_t FAMILY_ADDRESS_SIZE(int family) {
assert(IN_SET(family, AF_INET, AF_INET6));
return family == AF_INET6 ? 16 : 4;
switch (family) {
case AF_INET:
return 4;
case AF_INET6:
return 16;
default:
assert_not_reached();
}
}
#define FAMILY_ADDRESS_SIZE_SAFE(f) \

View File

@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <linux/if.h>
#include <linux/if.h> /* IWYU pragma: export */
#define IF_NAMESIZE 16

View File

@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <linux/if_arp.h>
#include <linux/if_arp.h> /* IWYU pragma: export */

View File

@@ -1,9 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <linux/in.h>
#include <linux/in6.h>
#include <linux/ipv6.h>
#include <linux/in.h> /* IWYU pragma: export */
#include <linux/in6.h> /* IWYU pragma: export */
#include <linux/ipv6.h> /* IWYU pragma: export */
#include <stddef.h>
#include <stdint.h>
#include <sys/socket.h>

View File

@@ -2,6 +2,7 @@
#pragma once
#include <features.h>
#include <linux/mount.h> /* IWYU pragma: export */
#include <stddef.h>
#include <stdint.h>
#include <sys/ioctl.h>

View File

@@ -6,9 +6,6 @@
#include "errno-util.h"
#include "initrd-util.h"
#include "log.h"
#include "parse-util.h"
#include "stat-util.h"
#include "string-util.h"
static int saved_in_initrd = -1;

Some files were not shown because too many files have changed in this diff Show More