inline static int backtrace2str(char* buf, int size)
{
void* bt[32];
int bt_size, i;
char** bt_strs;
char* p;
char* end;
char* next;
char* s;
char* e;
p=buf; end=buf+size;
bt_size=backtrace(bt, sizeof(bt)/sizeof(bt[0]));
bt_strs=backtrace_symbols(bt, bt_size);
if (bt_strs){
p=buf; end=buf+size;
/*if (bt_size>16) bt_size=16;*/ /* go up only 12 entries */
for (i=3; i< bt_size; i++){
/* try to isolate only the function name*/
s=strchr(bt_strs[i], '(');
if (s && ((e=strchr(s, ')'))!=0)){
s++;
}else if ((s=strchr(bt_strs[i], '['))!=0){
e=s+strlen(s);
}else{
s=bt_strs[i]; e=s+strlen(s); /* add thw whole string */
}
next=buf_append(p, end, s, (int)(long)(e-s));
if (next==0) break;
else p=next;
if (p<end){
*p=':'; /* separator */
p++;
}else break;
}
if (p==buf){
*p=0;
p++;
}else
*(p-1)=0;
free(bt_strs);
}
return (int)(long)(p-buf);
}