common.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * \file common.h
  3. *
  4. * \brief Utility macros for internal use in the library
  5. */
  6. /*
  7. * Copyright The Mbed TLS Contributors
  8. * SPDX-License-Identifier: Apache-2.0
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  11. * not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  18. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. */
  22. #ifndef MBEDTLS_LIBRARY_COMMON_H
  23. #define MBEDTLS_LIBRARY_COMMON_H
  24. #if defined(MBEDTLS_CONFIG_FILE)
  25. #include MBEDTLS_CONFIG_FILE
  26. #else
  27. #include "mbedtls/config.h"
  28. #endif
  29. /** Helper to define a function as static except when building invasive tests.
  30. *
  31. * If a function is only used inside its own source file and should be
  32. * declared `static` to allow the compiler to optimize for code size,
  33. * but that function has unit tests, define it with
  34. * ```
  35. * MBEDTLS_STATIC_TESTABLE int mbedtls_foo(...) { ... }
  36. * ```
  37. * and declare it in a header in the `library/` directory with
  38. * ```
  39. * #if defined(MBEDTLS_TEST_HOOKS)
  40. * int mbedtls_foo(...);
  41. * #endif
  42. * ```
  43. */
  44. #if defined(MBEDTLS_TEST_HOOKS)
  45. #define MBEDTLS_STATIC_TESTABLE
  46. #else
  47. #define MBEDTLS_STATIC_TESTABLE static
  48. #endif
  49. #endif /* MBEDTLS_LIBRARY_COMMON_H */