Initla commit

FossilOrigin-Name: 53b4bc73a86d7fb2348d9dbb030a1f250be017133b5c32df0cb153c35de89437
This commit is contained in:
7u83@mail.ru
2018-03-07 09:31:46 +00:00
parent c93867811a
commit accc0929cd
2 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,53 @@
#include <stdio.h>
#include "format.h"
/**
* Read hex bytes from a string to an uint8_t array
* @param dst destination array
* @param s string to read
* @param len length of string
* @return 0 if all was ok \n 1 if an error has occured.
*/
int cw_format_scan_hex_bytes(uint8_t *dst,const char *s, int len)
{
int rc ;
int err=0;
int val;
int c;
int i;
if ( len & 1){
rc = sscanf(s,"%01X",&c);
if (rc!=1){
c=0;
err=1;
}
*dst++=c;
s++;
len--;
}
for (i=0; i<len; i++){
rc = sscanf(s+i,"%01X",&c);
if (rc!=1){
c=0;
err=1;
}
if (!(i&1)) {
val = c<<4;
}
else{
val |= c;
*dst++=val;
}
}
return err;
}