1
0
mirror of https://github.com/cc65/cc65.git synced 2025-08-07 15:25:31 +00:00

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
This commit is contained in:
cuz
2003-11-06 18:04:07 +00:00
parent 8400fb848a
commit 6966ccda7e
15 changed files with 112 additions and 25 deletions

View File

@@ -13,7 +13,13 @@
FILE* fdopen (int handle, const char* /*mode*/) /*****************************************************************************/
/* Code */
/*****************************************************************************/
FILE* __fastcall__ fdopen (int handle, const char* /*mode*/)
{ {
FILE* f; FILE* f;

View File

@@ -20,7 +20,7 @@
int fgetc (FILE* f) int __fastcall__ fgetc (FILE* f)
{ {
unsigned char c; unsigned char c;

View File

@@ -5,15 +5,23 @@
*/ */
#include <stdio.h> #include <stdio.h>
int fgetpos(FILE* f, fpos_t *pos)
/*****************************************************************************/
/* Code */
/*****************************************************************************/
int __fastcall__ fgetpos (FILE* f, fpos_t* pos)
{ {
*pos = ftell (f); *pos = ftell (f);
if (*pos != -1) if (*pos != -1)
return 0; return 0;
return 1; return -1;
} }

View File

@@ -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 i = 0;
int c; int c;

View File

@@ -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 */ /* 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) { if ((f->f_flags & _FOPEN) == 0 || (f->f_flags & (_FERROR | _FEOF)) != 0) {

View File

@@ -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 */ /* Check if the file is open, if so, close it */
if ((f->f_flags & _FOPEN) == 0) { if ((f->f_flags & _FOPEN) == 0) {

View File

@@ -5,24 +5,32 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include "_file.h" #include "_file.h"
int fseek(FILE* f, long offset, int whence) /*****************************************************************************/
/* Code */
/*****************************************************************************/
int __fastcall__ fseek (FILE* f, long offset, int whence)
{ {
long res; long res;
/* Is the file open? */ /* Is the file open? */
if ((f->f_flags & _FOPEN) == 0) { if ((f->f_flags & _FOPEN) == 0) {
_errno = EINVAL; /* File not open */ _errno = EINVAL; /* File not open */
return 1; return -1;
} }
res = lseek(f->f_fd, offset, whence); res = lseek(f->f_fd, offset, whence);
if (res == -1L) return 1; if (res == -1L) return -1;
return 0; return 0;
} }

View File

@@ -5,11 +5,20 @@
*/ */
#include <stdio.h> #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); return fseek (f, (fpos_t)*pos, SEEK_SET);
} }

View File

@@ -5,13 +5,21 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include "_file.h" #include "_file.h"
long ftell(FILE* f)
/*****************************************************************************/
/* Code */
/*****************************************************************************/
long __fastcall__ ftell (FILE* f)
{ {
long pos; long pos;

View File

@@ -7,13 +7,17 @@
#include <stdio.h> #include <stdio.h>
#undef getchar /* This is usually declared as a macro */
/* This is usually declared as a macro */
#undef getchar
int getchar (void) /*****************************************************************************/
/* Code */
/*****************************************************************************/
int __fastcall__ getchar (void)
{ {
return fgetc (stdin); return fgetc (stdin);
} }

View File

@@ -11,7 +11,13 @@
char* gets (char* s) /*****************************************************************************/
/* Code */
/*****************************************************************************/
char* __fastcall__ gets (char* s)
{ {
int c; int c;
int i = 0; int i = 0;
@@ -49,3 +55,4 @@ char* gets (char* s)

View File

@@ -7,13 +7,17 @@
#include <stdio.h> #include <stdio.h>
#undef putchar /* This is usually declared as a macro */
/* This is usually declared as a macro */
#undef putchar
int putchar (int c) /*****************************************************************************/
/* Code */
/*****************************************************************************/
int __fastcall__ putchar (int c)
{ {
return fputc (c, stdout); return fputc (c, stdout);
} }

View File

@@ -13,7 +13,13 @@
int puts (const char* s) /*****************************************************************************/
/* Code */
/*****************************************************************************/
int __fastcall__ puts (const char* s)
{ {
static char nl = '\n'; static char nl = '\n';

View File

@@ -5,12 +5,21 @@
*/ */
#include <stdio.h> #include <stdio.h>
void rewind(FILE* f)
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void __fastcall__ rewind (FILE* f)
{ {
fseek(f, 0L, SEEK_SET); fseek(f, 0L, SEEK_SET);
clearerr(f); clearerr(f);
} }

View File

@@ -9,7 +9,7 @@
#include <stdio.h> #include <stdio.h>
#include "_scanf.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 */ /* Standard C function */
{ {
struct indesc id; struct indesc id;