2000-05-28 13:40:48 +00:00
|
|
|
/*
|
2002-03-24 13:26:18 +00:00
|
|
|
* fgetc.c
|
|
|
|
*
|
|
|
|
* (C) Copyright 1998, 2002 Ullrich von Bassewitz (uz@cc65.org)
|
2000-05-28 13:40:48 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2003-06-12 18:08:23 +00:00
|
|
|
#include <unistd.h>
|
2000-05-28 13:40:48 +00:00
|
|
|
#include "_file.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-03-24 13:26:18 +00:00
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Code */
|
2002-03-24 13:26:18 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-05-13 21:13:51 +00:00
|
|
|
int __fastcall__ fgetc (register FILE* f)
|
2000-05-28 13:40:48 +00:00
|
|
|
{
|
2002-03-24 13:26:18 +00:00
|
|
|
unsigned char c;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* 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) {
|
2013-05-09 11:56:54 +00:00
|
|
|
return EOF;
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
2004-05-13 21:13:51 +00:00
|
|
|
/* If we have a pushed back character, return it */
|
|
|
|
if (f->f_flags & _FPUSHBACK) {
|
|
|
|
f->f_flags &= ~_FPUSHBACK;
|
|
|
|
return f->f_pushback;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read one byte */
|
2000-05-28 13:40:48 +00:00
|
|
|
switch (read (f->f_fd, &c, 1)) {
|
|
|
|
|
|
|
|
case -1:
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Error */
|
|
|
|
f->f_flags |= _FERROR;
|
|
|
|
return EOF;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
case 0:
|
2013-05-09 11:56:54 +00:00
|
|
|
/* EOF */
|
|
|
|
f->f_flags |= _FEOF;
|
|
|
|
return EOF;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
default:
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Char read */
|
|
|
|
return c;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|