From 4e495c6fccc35f651a0898b187cbf3f0e220e070 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Thu, 16 Jan 2014 18:41:55 +0900 Subject: [PATCH] [WIP] add a buffer for ungetc --- include/picrin/port.h | 8 ++++++++ src/port.c | 2 ++ 2 files changed, 10 insertions(+) diff --git a/include/picrin/port.h b/include/picrin/port.h index dd5b8ae0..4d12d6e7 100644 --- a/include/picrin/port.h +++ b/include/picrin/port.h @@ -15,11 +15,19 @@ enum pic_port_status { PIC_PORT_CLOSE, }; +#define PIC_UBUFSIZ 3 + typedef struct { + /* buffered IO */ char *buf; int mode; int bufsiz; char *s, *c, *e; + /* ungetc buf */ + char ub[PIC_UBUFSIZ]; + int us; + int ur; + /* operators */ struct { void *cookie; int (*read)(void *, char *, int); diff --git a/src/port.c b/src/port.c index b6f4845c..3a48c940 100644 --- a/src/port.c +++ b/src/port.c @@ -94,6 +94,8 @@ pic_funopen(void *cookie, file->buf = NULL; file->mode = _IONBF; file->bufsiz = 0; + file->us = PIC_UBUFSIZ; + file->ur = 0; /* set vtable */ file->vtable.cookie = cookie; file->vtable.read = read;