1 /* SPDX-License-Identifier: MIT */
3 * Copyright (C) 2016 The Android Open Source Project
6 #if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION)
7 #error "Never include this file directly, include libavb.h instead."
10 #ifndef AVB_SYSDEPS_H_
11 #define AVB_SYSDEPS_H_
17 /* Change these includes to match your platform to bring in the
18 * equivalent types available in a normal C runtime. At least things
19 * like uint8_t, uint64_t, and bool (with |false|, |true| keywords)
24 /* If you don't have gcc or clang, these attribute macros may need to
27 #define AVB_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
28 #define AVB_ATTR_PACKED __attribute__((packed))
29 #define AVB_ATTR_NO_RETURN __attribute__((noreturn))
30 #define AVB_ATTR_SENTINEL __attribute__((__sentinel__))
32 /* Size in bytes used for alignment. */
34 #define AVB_ALIGNMENT_SIZE 8
36 #define AVB_ALIGNMENT_SIZE 4
39 /* Compare |n| bytes in |src1| and |src2|.
41 * Returns an integer less than, equal to, or greater than zero if the
42 * first |n| bytes of |src1| is found, respectively, to be less than,
43 * to match, or be greater than the first |n| bytes of |src2|. */
44 int avb_memcmp(const void* src1,
46 size_t n) AVB_ATTR_WARN_UNUSED_RESULT;
48 /* Compare two strings.
50 * Return an integer less than, equal to, or greater than zero if |s1|
51 * is found, respectively, to be less than, to match, or be greater
54 int avb_strcmp(const char* s1, const char* s2);
56 /* Compare |n| bytes in two strings.
58 * Return an integer less than, equal to, or greater than zero if the
59 * first |n| bytes of |s1| is found, respectively, to be less than,
60 * to match, or be greater than the first |n| bytes of |s2|.
62 int avb_strncmp(const char* s1, const char* s2, size_t n);
64 /* Copy |n| bytes from |src| to |dest|. */
65 void* avb_memcpy(void* dest, const void* src, size_t n);
67 /* Set |n| bytes starting at |s| to |c|. Returns |dest|. */
68 void* avb_memset(void* dest, const int c, size_t n);
70 /* Prints out a message. The string passed must be a NUL-terminated
73 void avb_print(const char* message);
75 /* Prints out a vector of strings. Each argument must point to a
76 * NUL-terminated UTF-8 string and NULL should be the last argument.
78 void avb_printv(const char* message, ...) AVB_ATTR_SENTINEL;
80 /* Aborts the program or reboots the device. */
81 void avb_abort(void) AVB_ATTR_NO_RETURN;
83 /* Allocates |size| bytes. Returns NULL if no memory is available,
84 * otherwise a pointer to the allocated memory.
86 * The memory is not initialized.
88 * The pointer returned is guaranteed to be word-aligned.
90 * The memory should be freed with avb_free() when you are done with it.
92 void* avb_malloc_(size_t size) AVB_ATTR_WARN_UNUSED_RESULT;
94 /* Frees memory previously allocated with avb_malloc(). */
95 void avb_free(void* ptr);
97 /* Returns the lenght of |str|, excluding the terminating NUL-byte. */
98 size_t avb_strlen(const char* str) AVB_ATTR_WARN_UNUSED_RESULT;
100 /* Divide the |dividend| by 10 and saves back to the pointer. Return the
102 uint32_t avb_div_by_10(uint64_t* dividend);
108 #endif /* AVB_SYSDEPS_H_ */