From d44cdad9ce46b9e9ce3e52a729d6a13cd8c8a912 Mon Sep 17 00:00:00 2001 From: cuz Date: Thu, 13 May 2004 21:54:01 +0000 Subject: [PATCH] Add support for ungetc, fix non standard compliant behaviour git-svn-id: svn://svn.cc65.org/cc65/trunk@3037 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/common/ftell.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/libsrc/common/ftell.c b/libsrc/common/ftell.c index 5af340929..4e4746e03 100644 --- a/libsrc/common/ftell.c +++ b/libsrc/common/ftell.c @@ -1,7 +1,8 @@ /* * ftell.c * - * Christian Groessler, 07-Aug-2000 + * Christian Groessler, 2000-08-07 + * Ullrich von Bassewitz, 2004-05-13 */ @@ -19,7 +20,7 @@ -long __fastcall__ ftell (FILE* f) +long __fastcall__ ftell (register FILE* f) { long pos; @@ -29,7 +30,17 @@ long __fastcall__ ftell (FILE* f) return -1L; } - pos = lseek(f->f_fd, 0L, SEEK_CUR); - return pos; /* -1 for error, comes from lseek() */ + /* Call the low level function */ + pos = lseek (f->f_fd, 0L, SEEK_CUR); + + /* If we didn't have an error, correct the return value in case we have + * a pushed back character. + */ + if (pos > 0 && (f->f_flags & _FPUSHBACK)) { + --pos; + } + + /* -1 for error, comes from lseek() */ + return pos; } -- 2.39.5