VM
FossilOrigin-Name: 4bbb8402b5110003c6d19908b6fa9b4a7a6b5903ba1fa691eb93a49aa0f089f4
This commit is contained in:
@ -24,6 +24,7 @@
|
||||
#ifndef __BSTR_H
|
||||
#define __BSTR_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@ -46,7 +47,7 @@ extern int bstr_to_str(char *dst, bstr_t str,char * def);
|
||||
/**
|
||||
* Return the length of a bstr_t string.
|
||||
*/
|
||||
#define bstr_len(s) (*(s))
|
||||
#define bstr_len(s) (*((uint8_t*)(s)))
|
||||
|
||||
/**
|
||||
* Return the data of a bstr_t string.
|
||||
@ -77,6 +78,53 @@ static inline int bstr16_ncpy(uint8_t *dst,uint8_t*src,uint16_t len)
|
||||
return len+2;
|
||||
}
|
||||
|
||||
static inline uint8_t * bstr16_create(uint8_t *data, uint16_t len)
|
||||
{
|
||||
uint8_t * str = malloc(2+len*sizeof(uint8_t));
|
||||
if (!str)
|
||||
return 0;
|
||||
*((uint16_t*)str)=len;
|
||||
memcpy(str+2,data,len);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#define vendorstr_get_vendor_id(str)\
|
||||
( *((uint32_t*)((str)+2)))
|
||||
|
||||
#define vendorstr_set_vendor_id(str,id)\
|
||||
( *((uint32_t*)((str)+2)) = id)
|
||||
|
||||
#define vendorstr_len(str)\
|
||||
(*((uint16_t*)((str)+0)))
|
||||
|
||||
#define vendorstr_set_len(str,len)\
|
||||
(*((uint16_t*)((str)+0))=len)
|
||||
|
||||
#define vendorstr_data(str)\
|
||||
(((uint8_t*)(str))+6)
|
||||
|
||||
#define vendorstr_size(n)\
|
||||
(1+6+(len)*sizeof(uint8_t))
|
||||
|
||||
|
||||
static inline uint8_t * vendorstr_create(uint32_t vendor_id, uint8_t *data, uint8_t len)
|
||||
{
|
||||
uint8_t * str = malloc(vendorstr_size(len));
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
vendorstr_set_vendor_id(str,vendor_id);
|
||||
vendorstr_set_len(str,len);
|
||||
memcpy(vendorstr_data(str),data,len);
|
||||
*(vendorstr_data(str)+vendorstr_len(str))=0;
|
||||
return str;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user