Skip to content

Commit 1781870

Browse files
committed
fixed reading of files with multi-byte characters in FileStream
1 parent f761852 commit 1781870

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

simplecpp.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@ class FileStream : public simplecpp::TokenList::Stream {
377377
}
378378

379379
virtual int get() {
380-
lastCh = fgetc(file);
380+
unsigned char ch;
381+
const int res = fread(&ch, 1, 1, file);
382+
lastCh = (res != 1 && feof(file)) ? EOF : ch;
381383
return lastCh;
382384
}
383385
virtual int peek() {
@@ -386,7 +388,7 @@ class FileStream : public simplecpp::TokenList::Stream {
386388
return ch;
387389
}
388390
virtual void unget() {
389-
ungetc(lastCh, file);
391+
fseek(file, -1, SEEK_CUR);
390392
}
391393
virtual bool good() {
392394
return lastCh != EOF;

0 commit comments

Comments
 (0)