make readTextFile() better. (ignore newlines at the end and fail better on non-existing file)
This commit is contained in:
parent
7ac2394a61
commit
66717f7c35
|
@ -105,9 +105,16 @@ int readFile(char * filename, char * data, int len){
|
||||||
int readTextFile(char * filename, char * data, int len){
|
int readTextFile(char * filename, char * data, int len){
|
||||||
int readbytes;
|
int readbytes;
|
||||||
|
|
||||||
|
if(len<1) return -1;
|
||||||
readbytes=readFile(filename,data,len-1);
|
readbytes=readFile(filename,data,len-1);
|
||||||
if(len>=0)
|
if(readbytes<0){
|
||||||
data[readbytes]=0;
|
data[0]=0;
|
||||||
|
return readbytes;
|
||||||
|
};
|
||||||
|
data[readbytes]=0;
|
||||||
|
while(readbytes>0 && data[readbytes-1]<0x20){
|
||||||
|
data[--readbytes]=0;
|
||||||
|
};
|
||||||
return readbytes;
|
return readbytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue