Skip to content

Commit

Permalink
Support for compiling without mbed-tls
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSomeMan committed Apr 12, 2023
1 parent 560f744 commit 1f861ff
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/wrap_esp_err_to_name_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@

#include "wrap_esp_err_to_name_r.h"
#include <esp_err.h>

#define HAS_MBED_TLS 0

#if defined __has_include
#if __has_include("mbedtls/error.h")
#undef HAS_MBED_TLS
#define HAS_MBED_TLS 1
#endif
#endif

#if HAS_MBED_TLS
#include "mbedtls/error.h"
#include "esp_tls.h"
#endif

const char*
wrap_esp_err_to_name_r(const esp_err_t code, char* const p_buf, const size_t buf_len)
Expand All @@ -32,13 +44,17 @@ wrap_esp_err_to_name_r(const esp_err_t code, char* const p_buf, const size_t buf
return p_buf;
}

#if HAS_MBED_TLS
mbedtls_strerror(code, p_buf, buf_len);

const char* const p_unknown_error_code_prefix = "UNKNOWN ERROR CODE (";
if (0 == strncmp(p_unknown_error_code_prefix, p_buf, strlen(p_unknown_error_code_prefix)))
{
(void)snprintf(p_buf, buf_len, "%s 0x%x(%d)", g_esp_unknown_msg, code, code);
}
#else
(void)snprintf(p_buf, buf_len, "%s 0x%x(%d)", g_esp_unknown_msg, code, code);
#endif

return p_buf;
}

0 comments on commit 1f861ff

Please sign in to comment.