From da185cd04d56746a5e66bb7c25cf07865aab9869 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Thu, 10 Feb 2022 17:19:27 +0100 Subject: [PATCH] tree-wide: move `unsigned` to the start of type declaration Even though ISO C11 doesn't mandate in which order the type specifiers should appear, having `unsigned` at the beginning of each type declaration feels more natural and, more importantly, it unbreaks Coccinelle, which has a hard time parsing `long unsigned` and others: ``` init_defs_builtins: /usr/lib64/coccinelle/standard.h init_defs: /home/mrc0mmand/repos/systemd/coccinelle/macros.h HANDLING: src/shared/mount-util.c : 1: strange type1, maybe because of weird order: long unsigned ``` Most of the codebase already "complies", so let's fix the remaining "offenders". --- src/basic/parse-util.c | 2 +- src/basic/parse-util.h | 12 ++++++------ src/basic/process-util.c | 4 ++-- src/core/bpf/restrict_fs/restrict-fs.bpf.c | 2 +- src/shared/mount-util.c | 4 ++-- src/shared/mount-util.h | 2 +- src/test/test-mountpoint-util.c | 2 +- src/test/test-sizeof.c | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c index 2888ab6523f..222b2304cd0 100644 --- a/src/basic/parse-util.c +++ b/src/basic/parse-util.c @@ -415,7 +415,7 @@ int safe_atoi(const char *s, int *ret_i) { return 0; } -int safe_atollu_full(const char *s, unsigned base, long long unsigned *ret_llu) { +int safe_atollu_full(const char *s, unsigned base, unsigned long long *ret_llu) { char *x = NULL; unsigned long long l; diff --git a/src/basic/parse-util.h b/src/basic/parse-util.h index 3dc5e140c9a..8273124626f 100644 --- a/src/basic/parse-util.h +++ b/src/basic/parse-util.h @@ -65,9 +65,9 @@ static inline int safe_atoi32(const char *s, int32_t *ret_i) { return safe_atoi(s, (int*) ret_i); } -int safe_atollu_full(const char *s, unsigned base, long long unsigned *ret_llu); +int safe_atollu_full(const char *s, unsigned base, unsigned long long *ret_llu); -static inline int safe_atollu(const char *s, long long unsigned *ret_llu) { +static inline int safe_atollu(const char *s, unsigned long long *ret_llu) { return safe_atollu_full(s, 0, ret_llu); } @@ -82,12 +82,12 @@ static inline int safe_atoi64(const char *s, int64_t *ret_i) { } static inline int safe_atoux64(const char *s, uint64_t *ret) { - assert_cc(sizeof(int64_t) == sizeof(long long unsigned)); - return safe_atollu_full(s, 16, (long long unsigned*) ret); + assert_cc(sizeof(int64_t) == sizeof(unsigned long long)); + return safe_atollu_full(s, 16, (unsigned long long*) ret); } #if LONG_MAX == INT_MAX -static inline int safe_atolu_full(const char *s, unsigned base, long unsigned *ret_u) { +static inline int safe_atolu_full(const char *s, unsigned base, unsigned long *ret_u) { assert_cc(sizeof(unsigned long) == sizeof(unsigned)); return safe_atou_full(s, base, (unsigned*) ret_u); } @@ -117,7 +117,7 @@ static inline int safe_atozu(const char *s, size_t *ret_u) { } #else static inline int safe_atozu(const char *s, size_t *ret_u) { - assert_cc(sizeof(size_t) == sizeof(long unsigned)); + assert_cc(sizeof(size_t) == sizeof(unsigned long)); return safe_atolu(s, ret_u); } #endif diff --git a/src/basic/process-util.c b/src/basic/process-util.c index c9718521584..0bf7448043c 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -645,7 +645,7 @@ int get_process_environ(pid_t pid, char **ret) { int get_process_ppid(pid_t pid, pid_t *ret) { _cleanup_free_ char *line = NULL; - long unsigned ppid; + unsigned long ppid; const char *p; int r; @@ -688,7 +688,7 @@ int get_process_ppid(pid_t pid, pid_t *ret) { if (ppid == 0) return -EADDRNOTAVAIL; - if ((pid_t) ppid < 0 || (long unsigned) (pid_t) ppid != ppid) + if ((pid_t) ppid < 0 || (unsigned long) (pid_t) ppid != ppid) return -ERANGE; if (ret) diff --git a/src/core/bpf/restrict_fs/restrict-fs.bpf.c b/src/core/bpf/restrict_fs/restrict-fs.bpf.c index cdc0613a019..99940bedfd8 100644 --- a/src/core/bpf/restrict_fs/restrict-fs.bpf.c +++ b/src/core/bpf/restrict_fs/restrict-fs.bpf.c @@ -16,7 +16,7 @@ #include struct super_block { - long unsigned int s_magic; + unsigned long int s_magic; } __attribute__((preserve_access_index)); struct inode { diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c index c75c02f5be3..6e938fc19db 100644 --- a/src/shared/mount-util.c +++ b/src/shared/mount-util.c @@ -592,9 +592,9 @@ int mode_to_inaccessible_node( return 0; } -int mount_flags_to_string(long unsigned flags, char **ret) { +int mount_flags_to_string(unsigned long flags, char **ret) { static const struct { - long unsigned flag; + unsigned long flag; const char *name; } map[] = { { .flag = MS_RDONLY, .name = "MS_RDONLY", }, diff --git a/src/shared/mount-util.h b/src/shared/mount-util.h index ce73aebd4bc..9caf92308a6 100644 --- a/src/shared/mount-util.h +++ b/src/shared/mount-util.h @@ -94,7 +94,7 @@ int mount_option_mangle( char **ret_remaining_options); int mode_to_inaccessible_node(const char *runtime_dir, mode_t mode, char **dest); -int mount_flags_to_string(long unsigned flags, char **ret); +int mount_flags_to_string(unsigned long flags, char **ret); /* Useful for usage with _cleanup_(), unmounts, removes a directory and frees the pointer */ static inline char* umount_and_rmdir_and_free(char *p) { diff --git a/src/test/test-mountpoint-util.c b/src/test/test-mountpoint-util.c index a373c5f98c3..3c2523006a4 100644 --- a/src/test/test-mountpoint-util.c +++ b/src/test/test-mountpoint-util.c @@ -18,7 +18,7 @@ #include "tmpfile-util.h" static void test_mount_propagation_flags_one(const char *name, int ret, unsigned long expected) { - long unsigned flags; + unsigned long flags; log_info("/* %s(%s) */", __func__, name); diff --git a/src/test/test-sizeof.c b/src/test/test-sizeof.c index f349852553d..55bd81e22fd 100644 --- a/src/test/test-sizeof.c +++ b/src/test/test-sizeof.c @@ -53,8 +53,8 @@ int main(void) { info(unsigned char); info(short unsigned); info(unsigned); - info(long unsigned); - info(long long unsigned); + info(unsigned long); + info(unsigned long long); info(__syscall_ulong_t); info(__syscall_slong_t); info(intmax_t);