author | ecalot
<ecalot> 2005-03-25 05:51:30 UTC |
committer | ecalot
<ecalot> 2005-03-25 05:51:30 UTC |
parent | ac902d8ac0f69d1e30a80cf12abea150d5210947 |
FP/src/res/dat.c | +1 | -1 |
FP/src/res/disk.c | +4 | -6 |
diff --git a/FP/src/res/dat.c b/FP/src/res/dat.c index b4a2f57..dc010a5 100644 --- a/FP/src/res/dat.c +++ b/FP/src/res/dat.c @@ -111,7 +111,7 @@ int mReadBeginDatFile(unsigned short int *numberOfItems,const char* vFiledat){ } int mReadFileInDatFile(int k,unsigned char* *data,unsigned long int *size) { - int ok=1; /* TODO: rename mRead* for mRead* and mWrite for mWrite */ + int ok=1; unsigned short int id; /* for each archived file the index is read */ diff --git a/FP/src/res/disk.c b/FP/src/res/disk.c index c412696..de95076 100644 --- a/FP/src/res/disk.c +++ b/FP/src/res/disk.c @@ -147,20 +147,15 @@ void addFileToOpenFilesList(const char* fileName,int hasBackup) { tOpenFiles* newNode; - /* Create the new node and fill in the fields */ newNode=(tOpenFiles*)malloc(sizeof(tOpenFiles)); newNode->next=openFilesList; newNode->name=strallocandcopy(fileName); if (hasBackup) { - newNode->size=mLoadFileArray(fileName,&(newNode->content)); - } else { - newNode->size=0; - } openFilesList=newNode; } @@ -228,6 +223,8 @@ int writeClose(FILE* fp,int dontSave,int optionflag,const char* backupExtension) if (fp==NULL) return -2; fwrite(content,1,size,fp); fclose(fp); + } else { + fclose(fp); } } @@ -416,7 +413,7 @@ int mLoadFileArray(const char* vFile,unsigned char** array) { /* get file size */ fseek(fp,0,SEEK_END); aux=ftell(fp); - if ( !aux || (aux>SIZE_OF_FILE) || ( ((*array=(unsigned char*)malloc(sizeof(char)*aux))==NULL) ) ) { + if ( !aux || (aux>SIZE_OF_FILE) || ( ((*array=(unsigned char*)malloc(aux+1))==NULL) ) ) { /* if the file was null or bigger than the max size or couldn't allocate the file in memory */ fclose(fp); return 0; @@ -424,6 +421,7 @@ int mLoadFileArray(const char* vFile,unsigned char** array) { /* if the file was successfully open */ fseek(fp,0,SEEK_SET); aux=fread (*array,1,aux,fp); + (*array)[aux]=0; fclose(fp); return aux; }