summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fgetc.c13
-rw-r--r--fgetc.h2
2 files changed, 11 insertions, 4 deletions
diff --git a/fgetc.c b/fgetc.c
index 7da6b24..f6a9e93 100644
--- a/fgetc.c
+++ b/fgetc.c
@@ -15,7 +15,7 @@ enum
GETC_BUFF_SIZE = 16
};
-static char getc_buffer[GETC_BUFF_SIZE] = { '\0' };
+static unsigned char getc_buffer[GETC_BUFF_SIZE] = { '\0' };
static long next_buffer_pos = 0; /* Next free position in the getc buffer. */
@@ -31,17 +31,24 @@ my_fgetc(FILE * input)
/* =============================== */
/* Pushes character back on input. */
/* =============================== */
-void
+int
my_ungetc(int c, FILE * input)
{
+ int rc;
+
if (next_buffer_pos >= GETC_BUFF_SIZE)
+ {
fprintf(stderr, "Error: cannot push back more than %d characters\n",
GETC_BUFF_SIZE);
+ rc = EOF;
+ }
else
{
- getc_buffer[next_buffer_pos++] = c;
+ rc = getc_buffer[next_buffer_pos++] = (unsigned char)c;
if (feof(input))
clearerr(input); /* No more EOF. */
}
+
+ return rc;
}
diff --git a/fgetc.h b/fgetc.h
index 3948588..4359d26 100644
--- a/fgetc.h
+++ b/fgetc.h
@@ -9,7 +9,7 @@
int
my_fgetc(FILE * input);
-void
+int
my_ungetc(int c, FILE * input);
#endif