diff options
-rw-r--r-- | src/fundamental/bootspec-fundamental.c | 6 | ||||
-rw-r--r-- | src/fundamental/bootspec-fundamental.h | 4 | ||||
-rw-r--r-- | src/fundamental/efivars-fundamental.c | 7 | ||||
-rw-r--r-- | src/fundamental/efivars-fundamental.h | 10 | ||||
-rw-r--r-- | src/fundamental/macro-fundamental.h | 20 | ||||
-rw-r--r-- | src/fundamental/meson.build | 1 | ||||
-rw-r--r-- | src/fundamental/string-util-fundamental.c | 10 | ||||
-rw-r--r-- | src/fundamental/string-util-fundamental.h | 16 | ||||
-rw-r--r-- | src/fundamental/types-fundamental.h | 39 |
9 files changed, 30 insertions, 83 deletions
diff --git a/src/fundamental/bootspec-fundamental.c b/src/fundamental/bootspec-fundamental.c index c0138926a5..4ba7c4c28d 100644 --- a/src/fundamental/bootspec-fundamental.c +++ b/src/fundamental/bootspec-fundamental.c @@ -2,7 +2,7 @@ #include "bootspec-fundamental.h" -sd_bool bootspec_pick_name_version_sort_key( +bool bootspec_pick_name_version_sort_key( const sd_char *os_pretty_name, const sd_char *os_image_id, const sd_char *os_name, @@ -47,7 +47,7 @@ sd_bool bootspec_pick_name_version_sort_key( good_sort_key = os_image_id ?: os_id; if (!good_name) - return sd_false; + return false; if (ret_name) *ret_name = good_name; @@ -58,5 +58,5 @@ sd_bool bootspec_pick_name_version_sort_key( if (ret_sort_key) *ret_sort_key = good_sort_key; - return sd_true; + return true; } diff --git a/src/fundamental/bootspec-fundamental.h b/src/fundamental/bootspec-fundamental.h index ff88f8bc3f..19b489ccf5 100644 --- a/src/fundamental/bootspec-fundamental.h +++ b/src/fundamental/bootspec-fundamental.h @@ -1,9 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "types-fundamental.h" +#include "string-util-fundamental.h" -sd_bool bootspec_pick_name_version_sort_key( +bool bootspec_pick_name_version_sort_key( const sd_char *os_pretty_name, const sd_char *os_image_id, const sd_char *os_name, diff --git a/src/fundamental/efivars-fundamental.c b/src/fundamental/efivars-fundamental.c index 1eaa455266..2ec3bfb2f0 100644 --- a/src/fundamental/efivars-fundamental.c +++ b/src/fundamental/efivars-fundamental.c @@ -16,12 +16,7 @@ const sd_char *secure_boot_mode_to_string(SecureBootMode m) { return (m >= 0 && m < _SECURE_BOOT_MAX) ? table[m] : NULL; } -SecureBootMode decode_secure_boot_mode( - sd_bool secure, - sd_bool audit, - sd_bool deployed, - sd_bool setup) { - +SecureBootMode decode_secure_boot_mode(bool secure, bool audit, bool deployed, bool setup) { /* See figure 32-4 Secure Boot Modes from UEFI Specification 2.9 */ if (secure && deployed && !audit && !setup) return SECURE_BOOT_DEPLOYED; diff --git a/src/fundamental/efivars-fundamental.h b/src/fundamental/efivars-fundamental.h index 9425455465..d1b70eafdc 100644 --- a/src/fundamental/efivars-fundamental.h +++ b/src/fundamental/efivars-fundamental.h @@ -4,10 +4,6 @@ #include <errno.h> #include "string-util-fundamental.h" -#ifndef UINT64_C -# define UINT64_C(c) (c ## ULL) -#endif - #define EFI_LOADER_FEATURE_CONFIG_TIMEOUT (UINT64_C(1) << 0) #define EFI_LOADER_FEATURE_CONFIG_TIMEOUT_ONE_SHOT (UINT64_C(1) << 1) #define EFI_LOADER_FEATURE_ENTRY_DEFAULT (UINT64_C(1) << 2) @@ -30,8 +26,4 @@ typedef enum SecureBootMode { } SecureBootMode; const sd_char *secure_boot_mode_to_string(SecureBootMode m); -SecureBootMode decode_secure_boot_mode( - sd_bool secure, - sd_bool audit, - sd_bool deployed, - sd_bool setup); +SecureBootMode decode_secure_boot_mode(bool secure, bool audit, bool deployed, bool setup); diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h index 18370ac46a..3c38afcab8 100644 --- a/src/fundamental/macro-fundamental.h +++ b/src/fundamental/macro-fundamental.h @@ -3,11 +3,12 @@ #ifndef SD_BOOT # include <assert.h> -# include <stddef.h> #endif #include <limits.h> -#include "types-fundamental.h" +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> #define _align_(x) __attribute__((__aligned__(x))) #define _alignas_(x) __attribute__((__aligned__(__alignof__(x)))) @@ -105,10 +106,10 @@ * on this macro will run concurrently to all other code conditionalized * the same way, there's no ordering or completion enforced. */ #define ONCE __ONCE(UNIQ_T(_once_, UNIQ)) -#define __ONCE(o) \ - ({ \ - static sd_bool (o) = sd_false; \ - __sync_bool_compare_and_swap(&(o), sd_false, sd_true); \ +#define __ONCE(o) \ + ({ \ + static bool (o) = false; \ + __sync_bool_compare_and_swap(&(o), false, true); \ }) #undef MAX @@ -258,7 +259,7 @@ #define IN_SET(x, ...) \ ({ \ - sd_bool _found = sd_false; \ + bool _found = false; \ /* If the build breaks in the line below, you need to extend the case macros. (We use "long double" as \ * type for the array, in the hope that checkers such as ubsan don't complain that the initializers for \ * the array are not representable by the base type. Ideally we'd use typeof(x) as base type, but that \ @@ -267,7 +268,7 @@ assert_cc(ELEMENTSOF(__assert_in_set) <= 20); \ switch (x) { \ FOR_EACH_MAKE_CASE(__VA_ARGS__) \ - _found = sd_true; \ + _found = true; \ break; \ default: \ break; \ @@ -299,9 +300,6 @@ }) static inline size_t ALIGN_TO(size_t l, size_t ali) { - /* sd-boot uses UINTN for size_t, let's make sure SIZE_MAX is correct. */ - assert_cc(SIZE_MAX == ~(size_t)0); - /* Check that alignment is exponent of 2 */ #if SIZE_MAX == UINT_MAX assert(__builtin_popcount(ali) == 1); diff --git a/src/fundamental/meson.build b/src/fundamental/meson.build index f927788c3a..2ec4a28433 100644 --- a/src/fundamental/meson.build +++ b/src/fundamental/meson.build @@ -8,7 +8,6 @@ fundamental_headers = files( 'macro-fundamental.h', 'sha256.h', 'string-util-fundamental.h', - 'types-fundamental.h', ) # for sd-boot diff --git a/src/fundamental/string-util-fundamental.c b/src/fundamental/string-util-fundamental.c index 169568e244..6f690b9c90 100644 --- a/src/fundamental/string-util-fundamental.c +++ b/src/fundamental/string-util-fundamental.c @@ -77,21 +77,21 @@ sd_char* endswith_no_case(const sd_char *s, const sd_char *postfix) { return (sd_char*) s + sl - pl; } -static sd_bool is_digit(sd_char a) { +static bool is_digit(sd_char a) { /* Locale-independent version of isdigit(). */ return a >= '0' && a <= '9'; } -static sd_bool is_alpha(sd_char a) { +static bool is_alpha(sd_char a) { /* Locale-independent version of isalpha(). */ return (a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z'); } -static sd_bool is_valid_version_char(sd_char a) { +static bool is_valid_version_char(sd_char a) { return is_digit(a) || is_alpha(a) || IN_SET(a, '~', '-', '^', '.'); } -sd_int strverscmp_improved(const sd_char *a, const sd_char *b) { +int strverscmp_improved(const sd_char *a, const sd_char *b) { /* This function is similar to strverscmp(3), but it treats '-' and '.' as separators. * * The logic is based on rpm's rpmvercmp(), but unlike rpmvercmp(), it distiguishes e.g. @@ -129,7 +129,7 @@ sd_int strverscmp_improved(const sd_char *a, const sd_char *b) { for (;;) { const sd_char *aa, *bb; - sd_int r; + int r; /* Drop leading invalid characters. */ while (*a != '\0' && !is_valid_version_char(*a)) diff --git a/src/fundamental/string-util-fundamental.h b/src/fundamental/string-util-fundamental.h index 8048a07f73..72fa0d7c90 100644 --- a/src/fundamental/string-util-fundamental.h +++ b/src/fundamental/string-util-fundamental.h @@ -18,8 +18,10 @@ # define strcasecmp strcasecmp16 # define strncasecmp strncasecmp16 # define STR_C(str) (L ## str) +typedef char16_t sd_char; #else # define STR_C(str) (str) +typedef char sd_char; #endif #define streq(a,b) (strcmp((a),(b)) == 0) @@ -27,25 +29,25 @@ #define strcaseeq(a,b) (strcasecmp((a),(b)) == 0) #define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0) -static inline sd_int strcmp_ptr(const sd_char *a, const sd_char *b) { +static inline int strcmp_ptr(const sd_char *a, const sd_char *b) { if (a && b) return strcmp(a, b); return CMP(a, b); } -static inline sd_int strcasecmp_ptr(const sd_char *a, const sd_char *b) { +static inline int strcasecmp_ptr(const sd_char *a, const sd_char *b) { if (a && b) return strcasecmp(a, b); return CMP(a, b); } -static inline sd_bool streq_ptr(const sd_char *a, const sd_char *b) { +static inline bool streq_ptr(const sd_char *a, const sd_char *b) { return strcmp_ptr(a, b) == 0; } -static inline sd_bool strcaseeq_ptr(const sd_char *a, const sd_char *b) { +static inline bool strcaseeq_ptr(const sd_char *a, const sd_char *b) { return strcasecmp_ptr(a, b) == 0; } @@ -63,7 +65,7 @@ sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) _pure_; sd_char *endswith(const sd_char *s, const sd_char *postfix) _pure_; sd_char *endswith_no_case(const sd_char *s, const sd_char *postfix) _pure_; -static inline sd_bool isempty(const sd_char *a) { +static inline bool isempty(const sd_char *a) { return !a || a[0] == '\0'; } @@ -71,7 +73,7 @@ static inline const sd_char *strempty(const sd_char *s) { return s ?: STR_C(""); } -static inline const sd_char *yes_no(sd_bool b) { +static inline const sd_char *yes_no(bool b) { return b ? STR_C("yes") : STR_C("no"); } @@ -79,7 +81,7 @@ static inline const sd_char* comparison_operator(int result) { return result < 0 ? STR_C("<") : result > 0 ? STR_C(">") : STR_C("=="); } -sd_int strverscmp_improved(const sd_char *a, const sd_char *b); +int strverscmp_improved(const sd_char *a, const sd_char *b); /* Like startswith(), but operates on arbitrary memory blocks */ static inline void *memory_startswith(const void *p, size_t sz, const sd_char *token) { diff --git a/src/fundamental/types-fundamental.h b/src/fundamental/types-fundamental.h deleted file mode 100644 index 5977e40c6c..0000000000 --- a/src/fundamental/types-fundamental.h +++ /dev/null @@ -1,39 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -/* This defines a number of basic types that are one thing in userspace and another in the UEFI environment, - * but mostly the same in concept and behaviour. - * - * Note: if the definition of these types/values has slightly different semantics in userspace and in the - * UEFI environment then please prefix its name with "sd_" to make clear these types have special semantics, - * and *we* defined them. Otherwise, if the types are effectively 100% identical in behaviour in userspace - * and UEFI environment you can omit the prefix. (Examples: sd_char is 8 bit in userspace and 16 bit in UEFI - * space hence it should have the sd_ prefix; but size_t in userspace and UINTN in UEFI environment are 100% - * defined the same way ultimately, hence it's OK to just define size_t as alias to UINTN in UEFI - * environment, so that size_t can be used everywhere, without any "sd_" prefix.) - * - * Note: we generally prefer the userspace names of types and concepts. i.e. if in doubt please name types - * after the userspace vocabulary, and let's keep UEFI vocabulary specific to the UEFI build environment. */ - -#ifdef SD_BOOT -#include <efi.h> - -typedef BOOLEAN sd_bool; -typedef CHAR16 sd_char; -typedef INTN sd_int; -typedef UINTN size_t; - -#define sd_true TRUE -#define sd_false FALSE -#else -#include <stdbool.h> -#include <stdint.h> - -typedef bool sd_bool; -typedef char sd_char; -typedef int sd_int; - -#define sd_true true -#define sd_false false - -#endif |