actube/src/cw/bstr_to_str.c
7u83@mail.ru f4ebe841a5 renamed capwap directory to cw.
FossilOrigin-Name: 8a43dd9d05a4cb73210243ddd8df2a26f16c7ef2c4d4e36ab446de1f65d88223
2016-03-03 19:46:20 +00:00

39 lines
580 B
C

#include <stdio.h>
#include <string.h>
#include "bstr.h"
#include "cw_util.h"
int bstr_to_str(char *dst, bstr_t str,char * def)
{
if (!str){
if (!def)
return 0;
return sprintf(dst,"%s",def);
}
int printable = cw_is_printable(bstr_data(str),bstr_len(str));
int l=bstr_len(str);
if (printable){
memcpy((char*)dst,bstr_data(str),l);
*(dst+l)=0;
return l;
}
int i;
int c=0;
char *s = dst;
for (i=0; i<l; i++){
if (!c){
s += sprintf(s,"%02X",bstr_data(str)[i]);
c=1;
}
else
s += sprintf(s,",%02X",bstr_data(str)[i]);
}
return s-dst;
}