replace old stdio functions with picrin's wrapper impls
This commit is contained in:
parent
86eb4bb64b
commit
392549b315
|
@ -41,6 +41,8 @@ struct pic_port *pic_stdin(pic_state *);
|
||||||
struct pic_port *pic_stdout(pic_state *);
|
struct pic_port *pic_stdout(pic_state *);
|
||||||
struct pic_port *pic_stderr(pic_state *);
|
struct pic_port *pic_stderr(pic_state *);
|
||||||
|
|
||||||
|
int pic_fflush(pic_file *);
|
||||||
|
|
||||||
pic_file *pic_funopen(void *cookie, int (*read)(void *, char *, int), int (*write)(void *, const char *, int), fpos_t (*seek)(void *, fpos_t, int), int (*close)(void *));
|
pic_file *pic_funopen(void *cookie, int (*read)(void *, char *, int), int (*write)(void *, const char *, int), fpos_t (*seek)(void *, fpos_t, int), int (*close)(void *));
|
||||||
|
|
||||||
pic_file *pic_fopen(const char *, const char *);
|
pic_file *pic_fopen(const char *, const char *);
|
||||||
|
|
|
@ -7,15 +7,15 @@ static pic_value
|
||||||
generic_open_file(pic_state *pic, const char *fname, char *mode, short flags)
|
generic_open_file(pic_state *pic, const char *fname, char *mode, short flags)
|
||||||
{
|
{
|
||||||
struct pic_port *port;
|
struct pic_port *port;
|
||||||
FILE *fp;
|
pic_file *file;
|
||||||
|
|
||||||
fp = fopen(fname, mode);
|
file = pic_fopen(fname, mode);
|
||||||
if (! fp) {
|
if (! file) {
|
||||||
pic_error(pic, "could not open file");
|
pic_error(pic, "could not open file");
|
||||||
}
|
}
|
||||||
|
|
||||||
port = (struct pic_port *)pic_obj_alloc(pic, sizeof(struct pic_port), PIC_TT_PORT);
|
port = (struct pic_port *)pic_obj_alloc(pic, sizeof(struct pic_port), PIC_TT_PORT);
|
||||||
port->file = fp;
|
port->file = file;
|
||||||
port->flags = flags;
|
port->flags = flags;
|
||||||
port->status = PIC_PORT_OPEN;
|
port->status = PIC_PORT_OPEN;
|
||||||
|
|
||||||
|
|
14
src/port.c
14
src/port.c
|
@ -359,7 +359,7 @@ pic_port_close_port(pic_state *pic)
|
||||||
|
|
||||||
pic_get_args(pic, "p", &port);
|
pic_get_args(pic, "p", &port);
|
||||||
|
|
||||||
if (fclose(port->file) == EOF) {
|
if (pic_fclose(port->file) == EOF) {
|
||||||
pic_error(pic, "close-port: failure");
|
pic_error(pic, "close-port: failure");
|
||||||
}
|
}
|
||||||
port->status = PIC_PORT_CLOSE;
|
port->status = PIC_PORT_CLOSE;
|
||||||
|
@ -404,7 +404,7 @@ pic_port_read_char(pic_state *pic)
|
||||||
|
|
||||||
assert_port_profile(port, PIC_PORT_IN | PIC_PORT_TEXT, PIC_PORT_OPEN, "read-char");
|
assert_port_profile(port, PIC_PORT_IN | PIC_PORT_TEXT, PIC_PORT_OPEN, "read-char");
|
||||||
|
|
||||||
if ((c = fgetc(port->file)) == EOF) {
|
if ((c = pic_fgetc(port->file)) == EOF) {
|
||||||
return pic_eof_object();
|
return pic_eof_object();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -422,11 +422,11 @@ pic_port_peek_char(pic_state *pic)
|
||||||
|
|
||||||
assert_port_profile(port, PIC_PORT_IN | PIC_PORT_TEXT, PIC_PORT_OPEN, "peek-char");
|
assert_port_profile(port, PIC_PORT_IN | PIC_PORT_TEXT, PIC_PORT_OPEN, "peek-char");
|
||||||
|
|
||||||
if ((c = fgetc(port->file)) == EOF) {
|
if ((c = pic_fgetc(port->file)) == EOF) {
|
||||||
return pic_eof_object();
|
return pic_eof_object();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ungetc(c, port->file);
|
pic_ungetc(c, port->file);
|
||||||
return pic_char_value(c);
|
return pic_char_value(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -450,7 +450,7 @@ pic_port_newline(pic_state *pic)
|
||||||
|
|
||||||
assert_port_profile(port, PIC_PORT_OUT | PIC_PORT_TEXT, PIC_PORT_OPEN, "newline");
|
assert_port_profile(port, PIC_PORT_OUT | PIC_PORT_TEXT, PIC_PORT_OPEN, "newline");
|
||||||
|
|
||||||
fputs("\n", port->file);
|
pic_fputs("\n", port->file);
|
||||||
return pic_none_value();
|
return pic_none_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -464,7 +464,7 @@ pic_port_write_char(pic_state *pic)
|
||||||
|
|
||||||
assert_port_profile(port, PIC_PORT_OUT | PIC_PORT_TEXT, PIC_PORT_OPEN, "write-char");
|
assert_port_profile(port, PIC_PORT_OUT | PIC_PORT_TEXT, PIC_PORT_OPEN, "write-char");
|
||||||
|
|
||||||
fputc(c, port->file);
|
pic_fputc(c, port->file);
|
||||||
return pic_none_value();
|
return pic_none_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,7 +477,7 @@ pic_port_flush(pic_state *pic)
|
||||||
|
|
||||||
assert_port_profile(port, PIC_PORT_OUT, PIC_PORT_OPEN, "flush-output-port");
|
assert_port_profile(port, PIC_PORT_OUT, PIC_PORT_OPEN, "flush-output-port");
|
||||||
|
|
||||||
fflush(port->file);
|
pic_fflush(port->file);
|
||||||
return pic_none_value();
|
return pic_none_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue