make readTextFile() better. (ignore newlines at the end and fail better on non-existing file)

This commit is contained in:
Stefan `Sec` Zehl 2012-04-18 01:23:01 +02:00
parent 7ac2394a61
commit 66717f7c35
1 changed files with 9 additions and 2 deletions

View File

@ -105,9 +105,16 @@ int readFile(char * filename, char * data, int len){
int readTextFile(char * filename, char * data, int len){
int readbytes;
if(len<1) return -1;
readbytes=readFile(filename,data,len-1);
if(len>=0)
if(readbytes<0){
data[0]=0;
return readbytes;
};
data[readbytes]=0;
while(readbytes>0 && data[readbytes-1]<0x20){
data[--readbytes]=0;
};
return readbytes;
};