fix include of files without last newline, as reported by Wes Hodges

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9032 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2006-03-22 08:15:46 +00:00
commit c2b8a083a0
2 changed files with 13 additions and 2 deletions

View file

@ -266,6 +266,7 @@ Swig_open(const String_or_char *name) {
String *
Swig_read_file(FILE *f) {
int len;
char buffer[4096];
String *str = NewStringEmpty();
@ -273,6 +274,14 @@ Swig_read_file(FILE *f) {
while (fgets(buffer,4095,f)) {
StringAppend(str,buffer);
}
len = StringLen(str);
if (len) {
char *cstr = Char(str);
if (cstr[len - 1] != '\n') {
StringAppend(str, "\n");
}
}
return str;
}