diff --git a/tools/ASR/linux/append b/tools/ASR/linux/append index 8c7bca6a9cd98a61e309b46d9f965a06ca0df168..1c227bf0ea13f82acb984a1faa213742e5cee211 100644 Binary files a/tools/ASR/linux/append and b/tools/ASR/linux/append differ diff --git a/tools/ASR/linux/append.c b/tools/ASR/linux/append.c index 75a71d8c8835a4a32d15064bde40d05d24ab5002..d0246919629f12c8eb664808c6bc0e8327372646 100644 --- a/tools/ASR/linux/append.c +++ b/tools/ASR/linux/append.c @@ -16,6 +16,7 @@ #define EADDR -4 #define ECREATE -5 #define ECMD -6 +#define EFREAD -7 #include #include @@ -47,7 +48,9 @@ static bool hexstr2int(char *str, int *out) static long fsize(FILE *fp) { fseek(fp, 0, SEEK_END); - return ftell(fp); + long size = ftell(fp); + fseek(fp, 0, SEEK_SET); + return size; } static char* shellcmd(char* cmd, char* buff, int size) @@ -194,38 +197,47 @@ int main(int argc, char *argv[]) } // get file size - FILE *fp = NULL; + FILE *fp1 = NULL, *fp2 = NULL; int file_size = 0; - fp = fopen(srcfile_abspath, "r"); - if(!fp) + fp1 = fopen(srcfile_abspath, "rb"); + if(!fp1) { ret = EFOUND; printf("Error(%d): srcfile not found.\n", ret); goto exit; } - file_size = fsize(fp); - fclose(fp); - fp = NULL; + file_size = fsize(fp1); // do patch - fp = fopen(patchfile_abspath, "w"); - if(!fp) + fp2 = fopen(patchfile_abspath, "wb"); + if(!fp2) { + fclose(fp1); ret = ECREATE; printf("Error(%d): patchfile create fail.\n", ret); goto exit; } - fwrite(addr_str, 1, strlen(addr_str), fp); - fwrite(&file_size, 1, 4, fp); - fclose(fp); + fwrite(addr_str, 1, strlen(addr_str), fp2); + fwrite(&file_size, 1, 4, fp2); - snprintf(cmd, sizeof(cmd), "cat %s >> %s", srcfile_abspath, patchfile_abspath); - if(ret = system(cmd)) + unsigned char rbuf[16384] = {0}; + int rret = 0; + while((rret = fread(rbuf, 1, sizeof(rbuf), fp1)) > 0) { - printf("Error(%d): patch fail.\n", ret); + fwrite(rbuf, 1, rret, fp2); + } + + fclose(fp1); + fclose(fp2); + + if(rret < 0) + { + ret = EFREAD; + remove(patchfile_abspath); + printf("Error(%d): crc fail.\n", ret); goto exit; } diff --git a/tools/ASR/linux/crc b/tools/ASR/linux/crc index 6a97c498b153f52875df297127f91c6e7ff7e093..3ba0ec2617a52cdf76c7ed7ff2ef736124473202 100644 Binary files a/tools/ASR/linux/crc and b/tools/ASR/linux/crc differ diff --git a/tools/ASR/linux/crc.c b/tools/ASR/linux/crc.c index 2e909aa4b63c6bbae03af0b354d9b6bc3ed7023c..99e5cb642a5d9dcaa4025f16e25cb12b45a6f949 100644 --- a/tools/ASR/linux/crc.c +++ b/tools/ASR/linux/crc.c @@ -16,6 +16,7 @@ #define EADDR -4 #define ECREATE -5 #define ECMD -6 +#define EFREAD -7 #include #include @@ -47,7 +48,9 @@ static bool hexstr2int(char *str, int *out) static long fsize(FILE *fp) { fseek(fp, 0, SEEK_END); - return ftell(fp); + long size = ftell(fp); + fseek(fp, 0, SEEK_SET); + return size; } static char* shellcmd(char* cmd, char* buff, int size) @@ -181,38 +184,46 @@ int main(int argc, char *argv[]) } // get file size - FILE *fp = NULL; + FILE *fp1 = NULL, *fp2 = NULL; int file_size = 0; - fp = fopen(srcfile_abspath, "r"); - if(!fp) + fp1 = fopen(srcfile_abspath, "rb"); + if(!fp1) { ret = EFOUND; printf("Error(%d): srcfile not found.\n", ret); goto exit; } - file_size = fsize(fp); - fclose(fp); - fp = NULL; + file_size = fsize(fp1); // do crc - fp = fopen(crcfile_abspath, "w"); - if(!fp) + fp2 = fopen(crcfile_abspath, "wb"); + if(!fp2) { + fclose(fp1); ret = ECREATE; printf("Error(%d): crcfile create fail.\n", ret); goto exit; } - int crc_dumy = 0x0; - fwrite(&file_size, 1, 4, fp); - fwrite(&crc_dumy, 1, 4, fp); - fclose(fp); - - snprintf(cmd, sizeof(cmd), "cat %s >> %s", srcfile_abspath, crcfile_abspath); - if(ret = system(cmd)) + fwrite(&file_size, 1, 4, fp2); + fwrite("=CRC", 1, 4, fp2); + + unsigned char rbuf[16384] = {0}; + int rret = 0; + while((rret = fread(rbuf, 1, sizeof(rbuf), fp1)) > 0) { + fwrite(rbuf, 1, rret, fp2); + } + + fclose(fp1); + fclose(fp2); + + if(rret < 0) + { + ret = EFREAD; + remove(crcfile_abspath); printf("Error(%d): crc fail.\n", ret); goto exit; } @@ -221,4 +232,4 @@ int main(int argc, char *argv[]) exit: return ret; -} +} \ No newline at end of file diff --git a/tools/ASR/win32/append.c b/tools/ASR/win32/append.c index 75a71d8c8835a4a32d15064bde40d05d24ab5002..d0246919629f12c8eb664808c6bc0e8327372646 100644 --- a/tools/ASR/win32/append.c +++ b/tools/ASR/win32/append.c @@ -16,6 +16,7 @@ #define EADDR -4 #define ECREATE -5 #define ECMD -6 +#define EFREAD -7 #include #include @@ -47,7 +48,9 @@ static bool hexstr2int(char *str, int *out) static long fsize(FILE *fp) { fseek(fp, 0, SEEK_END); - return ftell(fp); + long size = ftell(fp); + fseek(fp, 0, SEEK_SET); + return size; } static char* shellcmd(char* cmd, char* buff, int size) @@ -194,38 +197,47 @@ int main(int argc, char *argv[]) } // get file size - FILE *fp = NULL; + FILE *fp1 = NULL, *fp2 = NULL; int file_size = 0; - fp = fopen(srcfile_abspath, "r"); - if(!fp) + fp1 = fopen(srcfile_abspath, "rb"); + if(!fp1) { ret = EFOUND; printf("Error(%d): srcfile not found.\n", ret); goto exit; } - file_size = fsize(fp); - fclose(fp); - fp = NULL; + file_size = fsize(fp1); // do patch - fp = fopen(patchfile_abspath, "w"); - if(!fp) + fp2 = fopen(patchfile_abspath, "wb"); + if(!fp2) { + fclose(fp1); ret = ECREATE; printf("Error(%d): patchfile create fail.\n", ret); goto exit; } - fwrite(addr_str, 1, strlen(addr_str), fp); - fwrite(&file_size, 1, 4, fp); - fclose(fp); + fwrite(addr_str, 1, strlen(addr_str), fp2); + fwrite(&file_size, 1, 4, fp2); - snprintf(cmd, sizeof(cmd), "cat %s >> %s", srcfile_abspath, patchfile_abspath); - if(ret = system(cmd)) + unsigned char rbuf[16384] = {0}; + int rret = 0; + while((rret = fread(rbuf, 1, sizeof(rbuf), fp1)) > 0) { - printf("Error(%d): patch fail.\n", ret); + fwrite(rbuf, 1, rret, fp2); + } + + fclose(fp1); + fclose(fp2); + + if(rret < 0) + { + ret = EFREAD; + remove(patchfile_abspath); + printf("Error(%d): crc fail.\n", ret); goto exit; } diff --git a/tools/ASR/win32/append.exe b/tools/ASR/win32/append.exe index 3607c21e7f9f2dbd5a58e0bf4371bda103b65c0e..0d9f6258b9bef263d8c8c1e5f8d09baab167d350 100644 Binary files a/tools/ASR/win32/append.exe and b/tools/ASR/win32/append.exe differ diff --git a/tools/ASR/win32/crc.c b/tools/ASR/win32/crc.c index 2e119fd35bd2ee3386cbf93f88c2a7c2025952fd..99e5cb642a5d9dcaa4025f16e25cb12b45a6f949 100644 --- a/tools/ASR/win32/crc.c +++ b/tools/ASR/win32/crc.c @@ -16,6 +16,7 @@ #define EADDR -4 #define ECREATE -5 #define ECMD -6 +#define EFREAD -7 #include #include @@ -47,7 +48,9 @@ static bool hexstr2int(char *str, int *out) static long fsize(FILE *fp) { fseek(fp, 0, SEEK_END); - return ftell(fp); + long size = ftell(fp); + fseek(fp, 0, SEEK_SET); + return size; } static char* shellcmd(char* cmd, char* buff, int size) @@ -181,38 +184,46 @@ int main(int argc, char *argv[]) } // get file size - FILE *fp = NULL; + FILE *fp1 = NULL, *fp2 = NULL; int file_size = 0; - fp = fopen(srcfile_abspath, "r"); - if(!fp) + fp1 = fopen(srcfile_abspath, "rb"); + if(!fp1) { ret = EFOUND; printf("Error(%d): srcfile not found.\n", ret); goto exit; } - file_size = fsize(fp); - fclose(fp); - fp = NULL; + file_size = fsize(fp1); // do crc - fp = fopen(crcfile_abspath, "w"); - if(!fp) + fp2 = fopen(crcfile_abspath, "wb"); + if(!fp2) { + fclose(fp1); ret = ECREATE; printf("Error(%d): crcfile create fail.\n", ret); goto exit; } - int crc_dumy = 0x0; - fwrite(&file_size, 1, 4, fp); - fwrite(&crc_dumy, 1, 4, fp); - fclose(fp); - - snprintf(cmd, sizeof(cmd), "cat %s >> %s", srcfile_abspath, crcfile_abspath); - if(ret = system(cmd)) + fwrite(&file_size, 1, 4, fp2); + fwrite("=CRC", 1, 4, fp2); + + unsigned char rbuf[16384] = {0}; + int rret = 0; + while((rret = fread(rbuf, 1, sizeof(rbuf), fp1)) > 0) + { + fwrite(rbuf, 1, rret, fp2); + } + + fclose(fp1); + fclose(fp2); + + if(rret < 0) { + ret = EFREAD; + remove(crcfile_abspath); printf("Error(%d): crc fail.\n", ret); goto exit; } diff --git a/tools/ASR/win32/crc.exe b/tools/ASR/win32/crc.exe index 3fb109795bcefad54b5c3e6458b84fd687b46701..9d626788c97ab1e12e46a38f706a50e3fe2b3eb5 100644 Binary files a/tools/ASR/win32/crc.exe and b/tools/ASR/win32/crc.exe differ