summaryrefslogtreecommitdiff
path: root/win32/win32.c
diff options
context:
space:
mode:
Diffstat (limited to 'win32/win32.c')
-rw-r--r--win32/win32.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 0e155ef9e6..c4086fe159 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -51,7 +51,12 @@
#ifdef __BORLANDC__
# define _filbuf _fgetc
-# define _flsbuf fputc
+# define _flsbuf _fputc
+# define enough_to_get(n) (--(n) >= 0)
+# define enough_to_put(n) (++(n) < 0)
+#else
+# define enough_to_get(n) (--(n) >= 0)
+# define enough_to_put(n) (--(n) >= 0)
#endif
#if HAVE_WSAWAITFORMULTIPLEEVENTS
@@ -2788,7 +2793,7 @@ static void catch_interrupt(void)
int rb_w32_getc(FILE* stream)
{
int c, trap_immediate = rb_trap_immediate;
- if (--stream->FILE_COUNT >= 0) {
+ if (enough_to_get(stream->FILE_COUNT)) {
c = (unsigned char)*stream->FILE_READPTR++;
rb_trap_immediate = trap_immediate;
}
@@ -2810,7 +2815,7 @@ int rb_w32_getc(FILE* stream)
int rb_w32_putc(int c, FILE* stream)
{
int trap_immediate = rb_trap_immediate;
- if (--stream->FILE_COUNT >= 0) {
+ if (enough_to_put(stream->FILE_COUNT)) {
c = (unsigned char)(*stream->FILE_READPTR++ = (char)c);
rb_trap_immediate = trap_immediate;
}