From efb4cc9e37189b25cc22f8e0dd8a525d71ed4086 Mon Sep 17 00:00:00 2001 From: uz Date: Sun, 10 Jun 2012 19:02:54 +0000 Subject: [PATCH] Rearrangements for smaller size of generated code. git-svn-id: svn://svn.cc65.org/cc65/trunk@5704 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/common/fgets.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/libsrc/common/fgets.c b/libsrc/common/fgets.c index e65fb4bc8..d2e2c72e4 100644 --- a/libsrc/common/fgets.c +++ b/libsrc/common/fgets.c @@ -18,8 +18,9 @@ -char* __fastcall__ fgets (char* s, unsigned size, FILE* f) +char* __fastcall__ fgets (char* s, unsigned size, register FILE* f) { + register char* p = s; unsigned i; int c; @@ -34,28 +35,30 @@ char* __fastcall__ fgets (char* s, unsigned size, FILE* f) /* Get next character */ if ((c = fgetc (f)) == EOF) { - s[i] = '\0'; /* Error or EOF */ if ((f->f_flags & _FERROR) != 0 || i == 0) { /* ERROR or EOF on first char */ + *p = '\0'; return 0; } else { /* EOF with data already read */ break; - } + } } /* One char more */ - s[i++] = c; - - /* Stop at end of line */ - if (c == '\n') { - break; - } + *p = c; + ++p; + ++i; + + /* Stop at end of line */ + if ((char)c == '\n') { + break; + } } /* Terminate the string */ - s[i] = '\0'; + *p = '\0'; /* Done */ return s; -- 2.39.5