rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person |
| 5 | * obtaining a copy of this software and associated documentation |
| 6 | * files (the "Software"), to deal in the Software without |
| 7 | * restriction, including without limitation the rights to use, copy, |
| 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies |
| 9 | * of the Software, and to permit persons to whom the Software is |
| 10 | * furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | #include <assert.h> |
| 26 | #include <endian.h> |
| 27 | #include <lib/mempool.h> |
| 28 | #include <stdarg.h> |
| 29 | #include <stdio.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <string.h> |
| 32 | |
| 33 | #include "avb_sysdeps.h" |
| 34 | |
| 35 | int avb_memcmp(const void *src1, const void *src2, size_t n) |
| 36 | { |
| 37 | return memcmp(src1, src2, n); |
| 38 | } |
| 39 | |
| 40 | void *avb_memcpy(void *dest, const void *src, size_t n) |
| 41 | { |
| 42 | return memcpy(dest, src, n); |
| 43 | } |
| 44 | |
| 45 | void *avb_memset(void *dest, const int c, size_t n) |
| 46 | { |
| 47 | return memset(dest, c, n); |
| 48 | } |
| 49 | |
| 50 | int avb_strcmp(const char *s1, const char *s2) |
| 51 | { |
| 52 | return strcmp(s1, s2); |
| 53 | } |
| 54 | |
| 55 | size_t avb_strlen(const char *str) |
| 56 | { |
| 57 | return strlen(str); |
| 58 | } |
| 59 | |
| 60 | void avb_abort(void) |
| 61 | { |
| 62 | dprintf(ALWAYS, "Fatal ERROR,loop while"); |
| 63 | while (1); |
| 64 | } |
| 65 | |
| 66 | void avb_print(const char *message) |
| 67 | { |
| 68 | dprintf(ALWAYS, "%s", message); |
| 69 | } |
| 70 | |
| 71 | |
| 72 | void avb_printv(const char *message, ...) |
| 73 | { |
| 74 | va_list ap; |
| 75 | const char *m; |
| 76 | |
| 77 | va_start(ap, message); |
| 78 | for (m = message; m != NULL; m = va_arg(ap, const char *)) { |
| 79 | dprintf(ALWAYS, "%s", m); |
| 80 | } |
| 81 | va_end(ap); |
| 82 | } |
| 83 | |
| 84 | void *avb_malloc_(size_t size) |
| 85 | { |
| 86 | return mempool_alloc(size,MEMPOOL_ANY); |
| 87 | } |
| 88 | |
| 89 | void avb_free(void *ptr) |
| 90 | { |
| 91 | mempool_free(ptr); |
| 92 | } |
| 93 | |
| 94 | uint32_t avb_div_by_10(uint64_t *dividend) |
| 95 | { |
| 96 | uint32_t rem = (uint32_t)(*dividend % 10); |
| 97 | *dividend /= 10; |
| 98 | return rem; |
| 99 | } |