#include #include #include #define BTF_ID_FUNC_PFX "__BTF_ID__func__" static char *get_func_name(const char *sym) { char *func, *end; if (strncmp(sym, BTF_ID_FUNC_PFX, sizeof(BTF_ID_FUNC_PFX) - 1)) return NULL; /* Strip prefix */ func = strdup(sym + sizeof(BTF_ID_FUNC_PFX) - 1); /* Strip suffix */ end = strrchr(func, '_'); if (!end || *(end - 1) != '_') { free(func); return NULL; } *(end - 1) = '\0'; return func; } int main() { char *name = get_func_name("__BTF_ID__func__"); printf("name=%s\n", name); }