Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
tar.cpp
00001 #include "mbed.h" 00002 #include "tar.h" 00003 00004 FILE* fopenTar(char *tarfile, char *namefile) { 00005 00006 int i; 00007 char buf[32]; 00008 char sizeStr[12]; 00009 char *valExit = "error"; 00010 int size, offset = 0; 00011 00012 FILE *Tar = fopen(tarfile, "r"); 00013 00014 while(!feof(Tar)) { 00015 for(i=0; i <= strlen(namefile); i++) buf[i] = fgetc(Tar); 00016 00017 if(!strcmp(buf, namefile)) { 00018 valExit = ""; 00019 break; 00020 } 00021 00022 fseek(Tar , 124+offset , SEEK_SET); 00023 for(i=0; i < 12; i++) sizeStr[i] = fgetc(Tar); 00024 //printf("size string: %s; octal: %d; dec.: %x\n", sizeStr, atoi(sizeStr), oct2dec(atoi(sizeStr)) ); 00025 00026 size = oct2dec(atoi(sizeStr)); 00027 if(offset % 512 != 0) offset += (size/512 + 2)*512; 00028 else offset += (size/512 + 1)*512; 00029 00030 fseek(Tar , offset , SEEK_SET); 00031 } 00032 00033 if(valExit == "error") { 00034 printf("file \"%s\" not find in tar\n", namefile); 00035 return NULL; 00036 } else { 00037 fseek(Tar, offset+512 , SEEK_SET); 00038 return Tar; 00039 } 00040 } 00041 00042 int oct2dec(int n) /* Function to convert octal to decimal */ 00043 { 00044 int decimal=0, i=0, rem; 00045 while (n!=0) 00046 { 00047 rem = n%10; 00048 n/=10; 00049 decimal += rem*pow(8.0,i); 00050 ++i; 00051 } 00052 return decimal; 00053 }
Generated on Tue Jul 12 2022 15:05:43 by
1.7.2