bh_common.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _BH_COMMON_H
  6. #define _BH_COMMON_H
  7. #include "bh_platform.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #define bh_memcpy_s(dest, dlen, src, slen) \
  12. do { \
  13. int _ret = b_memcpy_s(dest, dlen, src, slen); \
  14. (void)_ret; \
  15. bh_assert(_ret == 0); \
  16. } while (0)
  17. #define bh_memcpy_wa(dest, dlen, src, slen) \
  18. do { \
  19. int _ret = b_memcpy_wa(dest, dlen, src, slen); \
  20. (void)_ret; \
  21. bh_assert(_ret == 0); \
  22. } while (0)
  23. #define bh_memmove_s(dest, dlen, src, slen) \
  24. do { \
  25. int _ret = b_memmove_s(dest, dlen, src, slen); \
  26. (void)_ret; \
  27. bh_assert(_ret == 0); \
  28. } while (0)
  29. #define bh_strcat_s(dest, dlen, src) \
  30. do { \
  31. int _ret = b_strcat_s(dest, dlen, src); \
  32. (void)_ret; \
  33. bh_assert(_ret == 0); \
  34. } while (0)
  35. #define bh_strcpy_s(dest, dlen, src) \
  36. do { \
  37. int _ret = b_strcpy_s(dest, dlen, src); \
  38. (void)_ret; \
  39. bh_assert(_ret == 0); \
  40. } while (0)
  41. int
  42. b_memcpy_s(void *s1, unsigned int s1max, const void *s2, unsigned int n);
  43. int
  44. b_memcpy_wa(void *s1, unsigned int s1max, const void *s2, unsigned int n);
  45. int
  46. b_memmove_s(void *s1, unsigned int s1max, const void *s2, unsigned int n);
  47. int
  48. b_strcat_s(char *s1, unsigned int s1max, const char *s2);
  49. int
  50. b_strcpy_s(char *s1, unsigned int s1max, const char *s2);
  51. /* strdup with string allocated by BH_MALLOC */
  52. char *
  53. bh_strdup(const char *s);
  54. /* strdup with string allocated by WA_MALLOC */
  55. char *
  56. wa_strdup(const char *s);
  57. #if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
  58. /* Executes a system command in bash/cmd.exe */
  59. int
  60. bh_system(const char *cmd);
  61. /* Tests whether can create a temporary file with the given name */
  62. bool
  63. bh_mkstemp(char *filename, size_t name_len);
  64. #endif
  65. #ifdef __cplusplus
  66. }
  67. #endif
  68. #endif