]> git.sur5r.net Git - cc65/blob - libsrc/common/fputc.c
fdae61768d78b01167d386c46e89a5a6b5de8cb7
[cc65] / libsrc / common / fputc.c
1 /*
2  * fputc.c
3  *
4  * Ullrich von Bassewitz, 02.06.1998
5  */
6
7
8
9 #include <stdio.h>
10 #include <fcntl.h>
11 #include "_file.h"
12
13
14
15 int fputc (int c, FILE* f)
16 {
17     /* Check if the file is open or if there is an error condition */
18     if ((f->f_flags & _FOPEN) == 0 || (f->f_flags & (_FERROR | _FEOF)) != 0) {
19         return EOF;
20     }
21
22     /* Write the byte (knows about byte order!) */
23     if (write (f->f_fd, &c, 1) <= 0) {
24         /* Error */
25         f->f_flags |= _FERROR;
26         return EOF;
27     }
28
29     /* Return the byte written */
30     return c & 0xFF;
31 }
32
33
34