From 6966ccda7ea952a6329055751c432b62c853dd8e Mon Sep 17 00:00:00 2001
From: cuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Date: Thu, 6 Nov 2003 18:04:07 +0000
Subject: [PATCH] Fixed the return code of fgetpos and ftell. Made lots of
 functions __fastcall__.

git-svn-id: svn://svn.cc65.org/cc65/trunk@2615 b7a2c559-68d2-44c3-8de9-860c34a00d81
---
 libsrc/common/fdopen.c  |  8 +++++++-
 libsrc/common/fgetc.c   |  2 +-
 libsrc/common/fgetpos.c | 12 ++++++++++--
 libsrc/common/fgets.c   |  8 +++++++-
 libsrc/common/fputc.c   |  8 +++++++-
 libsrc/common/freopen.c |  8 +++++++-
 libsrc/common/fseek.c   | 14 +++++++++++---
 libsrc/common/fsetpos.c | 11 ++++++++++-
 libsrc/common/ftell.c   | 10 +++++++++-
 libsrc/common/getchar.c | 12 ++++++++----
 libsrc/common/gets.c    |  9 ++++++++-
 libsrc/common/putchar.c | 12 ++++++++----
 libsrc/common/puts.c    |  8 +++++++-
 libsrc/common/rewind.c  | 11 ++++++++++-
 libsrc/common/vsscanf.c |  4 ++--
 15 files changed, 112 insertions(+), 25 deletions(-)

diff --git a/libsrc/common/fdopen.c b/libsrc/common/fdopen.c
index 19c94a977..6f0ea365a 100644
--- a/libsrc/common/fdopen.c
+++ b/libsrc/common/fdopen.c
@@ -13,7 +13,13 @@
 
 
 
-FILE* fdopen (int handle, const char* /*mode*/)
+/*****************************************************************************/
+/*     	    	     		     Code				     */
+/*****************************************************************************/
+
+
+
+FILE* __fastcall__ fdopen (int handle, const char* /*mode*/)
 {
     FILE* f;
 
diff --git a/libsrc/common/fgetc.c b/libsrc/common/fgetc.c
index c7d30d4bc..c84d8e662 100644
--- a/libsrc/common/fgetc.c
+++ b/libsrc/common/fgetc.c
@@ -20,7 +20,7 @@
 
 
 
-int fgetc (FILE* f)
+int __fastcall__ fgetc (FILE* f)
 {
     unsigned char c;
 
diff --git a/libsrc/common/fgetpos.c b/libsrc/common/fgetpos.c
index ae4b8c170..e3851f873 100644
--- a/libsrc/common/fgetpos.c
+++ b/libsrc/common/fgetpos.c
@@ -5,15 +5,23 @@
  */
 
 
+
 #include <stdio.h>
 
 
-int fgetpos(FILE* f, fpos_t *pos)
+
+/*****************************************************************************/
+/*     	    	     		     Code				     */
+/*****************************************************************************/
+
+
+
+int __fastcall__ fgetpos (FILE* f, fpos_t* pos)
 {
     *pos = ftell (f);
 
     if (*pos != -1)
         return 0;
-    return 1;
+    return -1;
 }
 
diff --git a/libsrc/common/fgets.c b/libsrc/common/fgets.c
index 18fc29a6c..ebfeb0866 100644
--- a/libsrc/common/fgets.c
+++ b/libsrc/common/fgets.c
@@ -12,7 +12,13 @@
 
 
 
-char* fgets (char* s, unsigned size, FILE* f)
+/*****************************************************************************/
+/*     	    	     		     Code				     */
+/*****************************************************************************/
+
+
+
+char* __fastcall__ fgets (char* s, unsigned size, FILE* f)
 {
     int i = 0;
     int c;
diff --git a/libsrc/common/fputc.c b/libsrc/common/fputc.c
index 2bb01a432..ef676a864 100644
--- a/libsrc/common/fputc.c
+++ b/libsrc/common/fputc.c
@@ -12,7 +12,13 @@
 
 
 
-int fputc (int c, FILE* f)
+/*****************************************************************************/
+/*     	    	     		     Code				     */
+/*****************************************************************************/
+
+
+
+int __fastcall__ fputc (int c, FILE* f)
 {
     /* Check if the file is open or if there is an error condition */
     if ((f->f_flags & _FOPEN) == 0 || (f->f_flags & (_FERROR | _FEOF)) != 0) {
diff --git a/libsrc/common/freopen.c b/libsrc/common/freopen.c
index da86b2685..b811badd8 100644
--- a/libsrc/common/freopen.c
+++ b/libsrc/common/freopen.c
@@ -13,7 +13,13 @@
 
 
 
-FILE* freopen (const char* name, const char* mode, FILE* f)
+/*****************************************************************************/
+/*     	    	     		     Code				     */
+/*****************************************************************************/
+
+
+
+FILE* __fastcall__ freopen (const char* name, const char* mode, FILE* f)
 {
     /* Check if the file is open, if so, close it */
     if ((f->f_flags & _FOPEN) == 0) {
diff --git a/libsrc/common/fseek.c b/libsrc/common/fseek.c
index 62d435e02..3ad4b1f85 100644
--- a/libsrc/common/fseek.c
+++ b/libsrc/common/fseek.c
@@ -5,24 +5,32 @@
  */
 
 
+
 #include <stdio.h>
 #include <errno.h>
 #include <unistd.h>
 #include "_file.h"
 
+		 
 
-int fseek(FILE* f, long offset, int whence)
+/*****************************************************************************/
+/*     	    	     		     Code				     */
+/*****************************************************************************/
+
+
+
+int __fastcall__ fseek (FILE* f, long offset, int whence)
 {
     long res;
 
     /* Is the file open? */
     if ((f->f_flags & _FOPEN) == 0) {
         _errno = EINVAL;                /* File not open */
-        return 1;
+        return -1;
     }
 
     res = lseek(f->f_fd, offset, whence);
-    if (res == -1L) return 1;
+    if (res == -1L) return -1;
     return 0;
 }
 
diff --git a/libsrc/common/fsetpos.c b/libsrc/common/fsetpos.c
index a04185a42..6194a109c 100644
--- a/libsrc/common/fsetpos.c
+++ b/libsrc/common/fsetpos.c
@@ -5,11 +5,20 @@
  */
 
 
+
 #include <stdio.h>
 
 
-int fsetpos(FILE* f, const fpos_t *pos)
+
+/*****************************************************************************/
+/*     	    	     		     Code				     */
+/*****************************************************************************/
+
+
+
+int __fastcall__ fsetpos (FILE* f, const fpos_t *pos)
 {
     return fseek (f, (fpos_t)*pos, SEEK_SET);
 }
 
+    
diff --git a/libsrc/common/ftell.c b/libsrc/common/ftell.c
index 317e3ee03..5af340929 100644
--- a/libsrc/common/ftell.c
+++ b/libsrc/common/ftell.c
@@ -5,13 +5,21 @@
  */
 
 
+
 #include <stdio.h>
 #include <errno.h>
 #include <unistd.h>
 #include "_file.h"
 
 
-long ftell(FILE* f)
+
+/*****************************************************************************/
+/*     	    	     		     Code				     */
+/*****************************************************************************/
+
+
+
+long __fastcall__ ftell (FILE* f)
 {
     long pos;
 
diff --git a/libsrc/common/getchar.c b/libsrc/common/getchar.c
index a058ab022..a37930df8 100644
--- a/libsrc/common/getchar.c
+++ b/libsrc/common/getchar.c
@@ -7,13 +7,17 @@
 
 
 #include <stdio.h>
-
-/* This is usually declared as a macro */
-#undef getchar
+#undef getchar		/* This is usually declared as a macro */
 
 
 
-int getchar (void)
+/*****************************************************************************/
+/*     	    	     		     Code				     */
+/*****************************************************************************/
+
+
+
+int __fastcall__ getchar (void)
 {
     return fgetc (stdin);
 }
diff --git a/libsrc/common/gets.c b/libsrc/common/gets.c
index b9dd00170..377e0ba53 100644
--- a/libsrc/common/gets.c
+++ b/libsrc/common/gets.c
@@ -11,7 +11,13 @@
 
 
 
-char* gets (char* s)
+/*****************************************************************************/
+/*     	    	     		     Code				     */
+/*****************************************************************************/
+
+
+
+char* __fastcall__ gets (char* s)
 {
     int c;
     int i = 0;
@@ -49,3 +55,4 @@ char* gets (char* s)
 
 
 
+		   
diff --git a/libsrc/common/putchar.c b/libsrc/common/putchar.c
index 95bee07d7..a98341a59 100644
--- a/libsrc/common/putchar.c
+++ b/libsrc/common/putchar.c
@@ -7,13 +7,17 @@
 
 
 #include <stdio.h>
-
-/* This is usually declared as a macro */
-#undef putchar
+#undef putchar	  	/* This is usually declared as a macro */
 
 
 
-int putchar (int c)
+/*****************************************************************************/
+/*     	    	     		     Code				     */
+/*****************************************************************************/
+
+
+
+int __fastcall__ putchar (int c)
 {
     return fputc (c, stdout);
 }
diff --git a/libsrc/common/puts.c b/libsrc/common/puts.c
index 18b2e9ab1..85b8cc315 100644
--- a/libsrc/common/puts.c
+++ b/libsrc/common/puts.c
@@ -13,7 +13,13 @@
 
 
 
-int puts (const char* s)
+/*****************************************************************************/
+/*     	    	     		     Code				     */
+/*****************************************************************************/
+
+
+
+int __fastcall__ puts (const char* s)
 {
     static char nl = '\n';
 
diff --git a/libsrc/common/rewind.c b/libsrc/common/rewind.c
index a4935b4a0..b6055ece5 100644
--- a/libsrc/common/rewind.c
+++ b/libsrc/common/rewind.c
@@ -5,12 +5,21 @@
  */
 
 
+
 #include <stdio.h>
 
 
-void rewind(FILE* f)
+
+/*****************************************************************************/
+/*     	    	     		     Code				     */
+/*****************************************************************************/
+
+
+
+void __fastcall__ rewind (FILE* f)
 {
     fseek(f, 0L, SEEK_SET);
     clearerr(f);
 }
 
+		  
diff --git a/libsrc/common/vsscanf.c b/libsrc/common/vsscanf.c
index 7dc28dcbb..95fcf5e9b 100644
--- a/libsrc/common/vsscanf.c
+++ b/libsrc/common/vsscanf.c
@@ -9,7 +9,7 @@
 
 #include <stdio.h>
 #include "_scanf.h"
-
+		 
 
 
 /*****************************************************************************/
@@ -31,7 +31,7 @@ static char get (struct indesc* d)
 
 
 
-int vsscanf (const char* str, const char* format, va_list ap)
+int __fastcall__ vsscanf (const char* str, const char* format, va_list ap)
 /* Standard C function */
 {
     struct indesc id;