handle correctly file rewind in the presence of ungetc (obs from Jose Santos).
This commit is contained in:
parent
5f0f91208d
commit
6ec92ac5c0
10
C/iopreds.c
10
C/iopreds.c
@ -3924,9 +3924,15 @@ static Int
|
|||||||
#if HAVE_FGETPOS
|
#if HAVE_FGETPOS
|
||||||
fpos_t rpos;
|
fpos_t rpos;
|
||||||
#endif
|
#endif
|
||||||
|
int ungetc_oldc = 0;
|
||||||
|
int had_ungetc = FALSE;
|
||||||
|
|
||||||
/* two cases where we can seek: memory and console */
|
/* two cases where we can seek: memory and console */
|
||||||
if (seekable) {
|
if (seekable) {
|
||||||
|
if (Stream[inp_stream].stream_getc == PlUnGetc) {
|
||||||
|
had_ungetc = TRUE;
|
||||||
|
ungetc_oldc = Stream[inp_stream].och;
|
||||||
|
}
|
||||||
if (Stream[inp_stream].status & InMemory_Stream_f) {
|
if (Stream[inp_stream].status & InMemory_Stream_f) {
|
||||||
cpos = Stream[inp_stream].u.mem_string.pos;
|
cpos = Stream[inp_stream].u.mem_string.pos;
|
||||||
} else {
|
} else {
|
||||||
@ -3946,6 +3952,10 @@ static Int
|
|||||||
if (Yap_Error_TYPE != YAP_NO_ERROR && seekable) {
|
if (Yap_Error_TYPE != YAP_NO_ERROR && seekable) {
|
||||||
H = old_H;
|
H = old_H;
|
||||||
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
|
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
|
||||||
|
if (had_ungetc) {
|
||||||
|
Stream[inp_stream].stream_getc = PlUnGetc;
|
||||||
|
Stream[inp_stream].och = ungetc_oldc;
|
||||||
|
}
|
||||||
if (Stream[inp_stream].status & InMemory_Stream_f) {
|
if (Stream[inp_stream].status & InMemory_Stream_f) {
|
||||||
Stream[inp_stream].u.mem_string.pos = cpos;
|
Stream[inp_stream].u.mem_string.pos = cpos;
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user