1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef LIBDTOVERLAY_SYSDEPS_H 18 #define LIBDTOVERLAY_SYSDEPS_H 19 20 /* Change these includes to match your platform to bring in the 21 * equivalent types available in a normal C runtime. At least things 22 * like uint8_t, uint64_t, and bool (with |false|, |true| keywords) 23 * must be present. 24 */ 25 #include <inttypes.h> 26 #include <stdbool.h> 27 #include <stddef.h> 28 #include <stdint.h> 29 30 #ifdef DTO_ENABLE_DEBUG 31 /* Print functions, used for diagnostics. 32 * 33 * These have no effect unless FDT_ENABLE_DEBUG is defined. 34 */ 35 #define dto_debug(...) \ 36 do { \ 37 dto_print("DEBUG: %s():", __func__); \ 38 dto_print(__VA_ARGS__); \ 39 } while (0) 40 #else 41 #define dto_debug(...) \ 42 do { \ 43 } while (0) 44 #endif 45 46 #ifndef DTO_DISABLE_ERROR_MSG 47 #define dto_error(...) \ 48 do { \ 49 dto_print("ERROR: %s():", __func__); \ 50 dto_print(__VA_ARGS__); \ 51 } while (0) 52 #else 53 #define dto_error(...) \ 54 do { \ 55 } while (0) 56 #endif 57 58 int dto_print(const char *fmt, ...); 59 60 void dto_qsort(void *base, size_t nmemb, size_t size, 61 int (*compar)(const void *, const void *)); 62 63 void *dto_malloc(size_t size); 64 65 void dto_free(void *ptr); 66 67 char *dto_strchr(const char *s, int c); 68 69 unsigned long int dto_strtoul(const char *nptr, char **endptr, int base); 70 71 size_t dto_strlen(const char *s); 72 73 int dto_memcmp(const void *lhs, const void *rhs, size_t n); 74 75 void *dto_memcpy(void *dest, const void *src, size_t n); 76 77 int dto_strcmp(const char *s1, const char *s2); 78 79 int dto_strncmp(const char *s1, const char *s2, size_t n); 80 81 void *dto_memchr(const void *s, int c, size_t n); 82 83 void *dto_memset(void *s, int c, size_t n); 84 85 #endif /* LIBDTOVERLAY_SYSDEPS_H */ 86