You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

64 lines
1.5 KiB

#include "basicReportRecord.h"
int char2int(char input){
if (input >= '0' && input <= '9')
return input - '0';
if (input >= 'A' && input <= 'F')
return input - 'A' + 10;
if (input >= 'a' && input <= 'f')
return input - 'a' + 10;
return -1;
};
// This function assumes src to be a zero terminated sanitized string with
// an even number of [0-9a-f] characters, and target to be sufficiently large
void hex2bin(CSTR src, uint8_t *target){
while (*src && src[1]){
*(target++) = char2int(*src) * 16 + char2int(src[1]);
src += 2;
};
};
bool eventGroupToMD5(uint8_t *evtGrp, CSTR md5){
sprintf(md5, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
evtGrp[0], evtGrp[1],
evtGrp[2], evtGrp[3],
evtGrp[4], evtGrp[5],
evtGrp[6], evtGrp[7],
evtGrp[8], evtGrp[9],
evtGrp[10], evtGrp[11],
evtGrp[12], evtGrp[13],
evtGrp[14], evtGrp[15]
);
return true;
};
bool MD5ToEventGroup(CSTR md5, uint8_t *evtGrp){
hex2bin(md5, evtGrp);
return true;
};
bool writeRecord(FILE *fd, ReportRecord *rec){
size_t RetVal;
RetVal = fwrite(rec, sizeof(ReportRecord), 1, fd);
if (RetVal == 1) return true;
return false;
};
bool readRecord(FILE *fd, ReportRecord *rec){
size_t RetVal;
RetVal = fread(rec, sizeof(ReportRecord), 1, fd);
if (RetVal == 1) return true;
return false;
};
size_t getRecordCountInFile(CSTR fName){
int RetVal;
struct stat cData;
RetVal = stat( fName, &cData );
if (RetVal == 0){
return (cData.st_size / sizeof(ReportRecord));
};
return 0;
};