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 <errno.h>
|
|
|
|
#include "_file.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-03-24 13:26:18 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Code */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-11-06 18:04:07 +00:00
|
|
|
int __fastcall__ fgetc (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) {
|
2002-03-24 13:26:18 +00:00
|
|
|
return EOF;
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the byte */
|
|
|
|
switch (read (f->f_fd, &c, 1)) {
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
/* Error */
|
|
|
|
f->f_flags |= _FERROR;
|
2002-03-24 13:26:18 +00:00
|
|
|
return EOF;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
case 0:
|
|
|
|
/* EOF */
|
|
|
|
f->f_flags |= _FEOF;
|
2002-03-24 13:26:18 +00:00
|
|
|
return EOF;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
/* Char read */
|
2002-03-24 13:26:18 +00:00
|
|
|
return c;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|