Home | History | Annotate | Download | only in libatap
      1 /*
      2  * Copyright 2017 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 ATAP_SYSDEPS_H_
     18 #define ATAP_SYSDEPS_H_
     19 
     20 #ifdef __cplusplus
     21 extern "C" {
     22 #endif
     23 
     24 /* Change these includes to match your platform to bring in the
     25  * equivalent types available in a normal C runtime. At least things
     26  * like uint8_t, uint64_t, and bool (with |false|, |true| keywords)
     27  * must be present.
     28  */
     29 #include <inttypes.h>
     30 #include <stdbool.h>
     31 #include <stddef.h>
     32 #include <stdint.h>
     33 
     34 /* If you don't have gcc or clang, these attribute macros may need to
     35  * be adjusted.
     36  */
     37 #define ATAP_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
     38 #define ATAP_ATTR_PACKED __attribute__((packed))
     39 #define ATAP_ATTR_NO_RETURN __attribute__((noreturn))
     40 #define ATAP_ATTR_SENTINEL __attribute__((__sentinel__))
     41 
     42 /* Copy |n| bytes from |src| to |dest|. */
     43 void* atap_memcpy(void* dest, const void* src, size_t n);
     44 
     45 /* Set |n| bytes starting at |s| to |c|.  Returns |dest|. */
     46 void* atap_memset(void* dest, const int c, size_t n);
     47 
     48 /* Aborts the program or reboots the device. */
     49 void atap_abort(void) ATAP_ATTR_NO_RETURN;
     50 
     51 /* Prints out a message. The string passed must be a NUL-terminated
     52  * UTF-8 string.
     53  */
     54 void atap_print(const char* message);
     55 
     56 /* Prints out a vector of strings. Each argument must point to a
     57  * NUL-terminated UTF-8 string and NULL should be the last argument.
     58  */
     59 void atap_printv(const char* message, ...) ATAP_ATTR_SENTINEL;
     60 
     61 /* Allocates |size| bytes. Returns NULL if no memory is available,
     62  * otherwise a pointer to the allocated memory.
     63  *
     64  * The memory is not initialized.
     65  *
     66  * The pointer returned is guaranteed to be word-aligned.
     67  *
     68  * The memory should be freed with atap_free() when you are done with it.
     69  */
     70 void* atap_malloc(size_t size) ATAP_ATTR_WARN_UNUSED_RESULT;
     71 
     72 /* Frees memory previously allocated with atap_malloc(). */
     73 void atap_free(void* ptr);
     74 
     75 /* Returns the length of |str|, excluding the terminating NUL-byte. */
     76 size_t atap_strlen(const char* str) ATAP_ATTR_WARN_UNUSED_RESULT;
     77 
     78 #ifdef __cplusplus
     79 }
     80 #endif
     81 
     82 #endif /* ATAP_SYSDEPS_H_ */
     83