OVMS3-idf/components/esp32/esp_err_to_name.c.in

54 lines
1.1 KiB
C
Raw Normal View History

@COMMENT@
#include <string.h>
#if __has_include("soc/soc.h")
#include "soc/soc.h"
#endif
@HEADERS@
#define ERR_TBL_IT(err) {err, #err}
typedef struct {
esp_err_t code;
const char *msg;
} esp_err_msg_t;
static const esp_err_msg_t esp_err_msg_table[] = {
@ERROR_ITEMS@
};
static const char esp_unknown_msg[] = "UNKNOWN ERROR";
const char *esp_err_to_name(esp_err_t code)
{
int i;
for (i = 0; i < sizeof(esp_err_msg_table)/sizeof(esp_err_msg_table[0]); ++i) {
if (esp_err_msg_table[i].code == code) {
return esp_err_msg_table[i].msg;
}
}
return esp_unknown_msg;
}
const char *esp_err_to_name_r(esp_err_t code, char *buf, size_t buflen)
{
int i;
for (i = 0; i < sizeof(esp_err_msg_table)/sizeof(esp_err_msg_table[0]); ++i) {
if (esp_err_msg_table[i].code == code) {
strlcpy(buf, esp_err_msg_table[i].msg, buflen);
return buf;
}
}
if (strerror_r(code, buf, buflen) == 0) {
return buf;
}
snprintf(buf, buflen, "Unknown error %d", code);
return buf;
}