]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
replaced the getline which does't support by minGW on windows
authordouniwan5788 <douniwan5788@ef4ab9da-24cd-11de-8aaa-f3a34680c41f>
Thu, 31 May 2012 09:46:02 +0000 (09:46 +0000)
committerdouniwan5788 <douniwan5788@ef4ab9da-24cd-11de-8aaa-f3a34680c41f>
Thu, 31 May 2012 09:46:02 +0000 (09:46 +0000)
client/cmdhfmf.c

index ac4f1087d131bcba3cd8d21dceadbe54dbbe1876..2d1c76d50e15ea91a2e8a518740fa02ac24a7417 100644 (file)
@@ -712,6 +712,7 @@ int CmdHF14AMfChk(const char *Cmd)
 {\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
@@ -810,20 +811,24 @@ int CmdHF14AMfChk(const char *Cmd)
                                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
@@ -835,11 +840,10 @@ int CmdHF14AMfChk(const char *Cmd)
                                                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
Impressum, Datenschutz