diff options
author | pgen <p.gen.progs@gmail.com> | 2021-07-10 15:00:11 +0200 |
---|---|---|
committer | pgen <p.gen.progs@gmail.com> | 2021-07-10 15:02:16 +0200 |
commit | 2ac8cc9f516ec5c5991ba22d48662a40c3bd6dd0 (patch) | |
tree | 932b7bebafd7a91d91e6b7a35b002cba91a26bfb | |
parent | 0b9536c75192b45977549a15345925e0d119f9c9 (diff) |
Fix my_ungetc
- reset EOF flag if necessary.
- make it POSIX compliant.
-rw-r--r-- | fgetc.c | 7 | ||||
-rw-r--r-- | fgetc.h | 2 | ||||
-rw-r--r-- | smenu.c | 4 |
3 files changed, 9 insertions, 4 deletions
@@ -32,11 +32,16 @@ my_fgetc(FILE * input) /* Pushes character back on input. */ /* =============================== */ void -my_ungetc(int c) +my_ungetc(int c, FILE * input) { if (next_buffer_pos >= GETC_BUFF_SIZE) fprintf(stderr, "Error: cannot push back more than %d characters\n", GETC_BUFF_SIZE); else + { getc_buffer[next_buffer_pos++] = c; + + if (feof(input)) + clearerr(input); /* No more EOF. */ + } } @@ -10,6 +10,6 @@ int my_fgetc(FILE * input); void -my_ungetc(int c); +my_ungetc(int c, FILE * input); #endif @@ -2755,10 +2755,10 @@ get_word(FILE * input, ll_t * word_delims_list, ll_t * record_delims_list, pos = strlen(utf8_buffer); while (pos > 0) - my_ungetc(utf8_buffer[--pos]); + my_ungetc(utf8_buffer[--pos], input); } else - my_ungetc(byte); + my_ungetc(byte, input); } /* Mark it as the last word of a record if its sequence matches a */ |