Implemented ferror
This commit is contained in:
7
photon/libc/stdio/ferror.c
Normal file
7
photon/libc/stdio/ferror.c
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <__fio.h>
|
||||||
|
|
||||||
|
int ferror(FILE *fp)
|
||||||
|
{
|
||||||
|
return __fio_error(fp);
|
||||||
|
}
|
||||||
@@ -5,5 +5,10 @@ int fputs(const char *str, FILE *fp)
|
|||||||
{
|
{
|
||||||
while (*str) {
|
while (*str) {
|
||||||
__fio_write(fp, str++, 1);
|
__fio_write(fp, str++, 1);
|
||||||
|
if (__fio_error(fp)) {
|
||||||
|
return EOF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,11 +11,13 @@ struct __io_file {
|
|||||||
char buf[__FIO_BUFSZ];
|
char buf[__FIO_BUFSZ];
|
||||||
unsigned int buf_idx;
|
unsigned int buf_idx;
|
||||||
unsigned int fd;
|
unsigned int fd;
|
||||||
|
char err;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern int __fileno(struct __io_file *f);
|
extern int __fileno(struct __io_file *f);
|
||||||
extern unsigned int __fio_write(struct __io_file *f, const char *buf, unsigned int sz);
|
extern unsigned int __fio_write(struct __io_file *f, const char *buf, unsigned int sz);
|
||||||
extern unsigned int __fio_flush(struct __io_file *f);
|
extern unsigned int __fio_flush(struct __io_file *f);
|
||||||
|
extern int __fio_error(struct __io_file *f);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,15 @@ unsigned int __fio_write(struct __io_file *f, const char *buf, unsigned int sz)
|
|||||||
|
|
||||||
unsigned int __fio_flush(struct __io_file *f)
|
unsigned int __fio_flush(struct __io_file *f)
|
||||||
{
|
{
|
||||||
write(f->fd, f->buf, f->buf_idx);
|
ssize_t res = write(f->fd, f->buf, f->buf_idx);
|
||||||
|
if (res != f->buf_idx) {
|
||||||
|
f->err = 1;
|
||||||
|
}
|
||||||
|
|
||||||
f->buf_idx = 0;
|
f->buf_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int __fio_error(struct __io_file *f)
|
||||||
|
{
|
||||||
|
return f->err != 0;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user