{\r
FILE * f;\r
char filename[256]={0};\r
+ uint8_t buf[13];\r
uint8_t *keyBlock = NULL, *p;\r
uint8_t stKeyBlock = 20;\r
\r
return 2;\r
}\r
\r
- char * line = NULL;\r
- size_t len = 0;\r
- ssize_t read;\r
if ( (f = fopen( filename , "r")) ) {\r
- while((read = getline(&line, &len, f)) != -1){\r
+ while( !feof(f) ){\r
+ memset(buf, 0, sizeof(buf));\r
+ fgets(buf, sizeof(buf), f);\r
+ \r
+ if (strlen(buf) < 12 || buf[11] == '\n')\r
+ continue;\r
\r
- if( line[0]=='#' || line[0]=='\n' ) continue; //The line start with # is remcommnet,skip\r
+ while (fgetc(f) != '\n' && !feof(f)) ; //goto next line\r
+ \r
+ if( buf[0]=='#' ) continue; //The line start with # is remcommnet,skip\r
\r
- if (read < 12 || !isxdigit(line[0])){\r
- PrintAndLog("File content error. '%s' must include 12 HEX symbols",line);\r
+ if (!isxdigit(buf[0])){\r
+ PrintAndLog("File content error. '%s' must include 12 HEX symbols",buf);\r
continue;\r
}\r
\r
- line[12] = 0;\r
+ buf[12] = 0;\r
\r
if ( stKeyBlock - keycnt < 2) {\r
p = realloc(keyBlock, 6*(stKeyBlock+=10));\r
keyBlock = p;\r
}\r
memset(keyBlock + 6 * keycnt, 0, 6);\r
- num_to_bytes(strtoll(line, NULL, 16), 6, keyBlock + 6*keycnt);\r
+ num_to_bytes(strtoll(buf, NULL, 16), 6, keyBlock + 6*keycnt);\r
PrintAndLog("chk custom key[%d] %012llx", keycnt, bytes_to_num(keyBlock + 6*keycnt, 6));\r
keycnt++;\r
}\r
- free(line);\r
} else {\r
PrintAndLog("File: %s: not found or locked.", filename);\r
free(keyBlock);\r