Implemented fputs
This commit is contained in:
@@ -13,6 +13,8 @@
|
|||||||
#define SEEK_CUR __SEEK_CUR
|
#define SEEK_CUR __SEEK_CUR
|
||||||
#define SEEK_END __SEEK_END
|
#define SEEK_END __SEEK_END
|
||||||
|
|
||||||
|
#define EOF -1
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@@ -24,6 +26,7 @@ extern FILE *stdout;
|
|||||||
extern FILE *stderr;
|
extern FILE *stderr;
|
||||||
|
|
||||||
extern int fileno(FILE *fp);
|
extern int fileno(FILE *fp);
|
||||||
|
extern int fputs(const char *str, FILE *fp);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|||||||
9
photon/libc/stdio/fputs.c
Normal file
9
photon/libc/stdio/fputs.c
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <__fio.h>
|
||||||
|
|
||||||
|
int fputs(const char *str, FILE *fp)
|
||||||
|
{
|
||||||
|
while (*str) {
|
||||||
|
__fio_write(fp, str++, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,8 @@ struct __io_file {
|
|||||||
};
|
};
|
||||||
|
|
||||||
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_flush(struct __io_file *f);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "__fio.h"
|
#include "__fio.h"
|
||||||
#include "__syscall.h"
|
#include "__syscall.h"
|
||||||
|
#include "unistd.h"
|
||||||
|
|
||||||
struct __io_file __stdin = {};
|
struct __io_file __stdin = {};
|
||||||
struct __io_file __stdout = {};
|
struct __io_file __stdout = {};
|
||||||
@@ -20,3 +21,25 @@ int __fileno(struct __io_file *f)
|
|||||||
{
|
{
|
||||||
return f->fd;
|
return f->fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int __fio_write(struct __io_file *f, const char *buf, unsigned int sz)
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < sz; i++) {
|
||||||
|
if (f->buf_idx >= __FIO_BUFSZ) {
|
||||||
|
__fio_flush(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
f->buf[f->buf_idx++] = buf[i];
|
||||||
|
if (buf[i] == '\n') {
|
||||||
|
__fio_flush(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sz;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int __fio_flush(struct __io_file *f)
|
||||||
|
{
|
||||||
|
write(f->fd, f->buf, f->buf_idx);
|
||||||
|
f->buf_idx = 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char *msg = "Hello!\n";
|
fputs("Hello, world!\n", stdout);
|
||||||
write(fileno(stdout), msg, 7);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user