From a6e71e47b80bda72764c7676f5209721bbebabdc Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sun, 18 Aug 2013 17:45:23 +0900 Subject: [PATCH] Adding port-fileno. --- eval.c | 9 +++++++++ include/chibi/eval.h | 2 ++ opcodes.c | 4 +++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/eval.c b/eval.c index b3fd1a28..219b1005 100644 --- a/eval.c +++ b/eval.c @@ -1178,6 +1178,15 @@ sexp sexp_set_port_line_op (sexp ctx, sexp self, sexp_sint_t n, sexp port, sexp return SEXP_VOID; } +#ifndef PLAN9 +sexp sexp_get_port_fileno (sexp ctx, sexp self, sexp_sint_t n, sexp port) { + sexp_assert_type(ctx, sexp_portp, SEXP_IPORT, port); + if (sexp_port_stream(port) && sexp_port_fileno(port) >= 0) + return sexp_make_fixnum(sexp_port_fileno(port)); + return SEXP_FALSE; +} +#endif + #if SEXP_USE_STATIC_LIBS #ifndef PLAN9 #include "clibs.c" diff --git a/include/chibi/eval.h b/include/chibi/eval.h index 901d5212..e54c3d5d 100644 --- a/include/chibi/eval.h +++ b/include/chibi/eval.h @@ -224,6 +224,8 @@ SEXP_API sexp sexp_9p_req_fid (sexp ctx, sexp self, sexp_sint_t n, sexp req); SEXP_API sexp sexp_9p_req_newfid (sexp ctx, sexp self, sexp_sint_t n, sexp req); SEXP_API sexp sexp_9p_respond (sexp ctx, sexp self, sexp_sint_t n, sexp req, sexp err); SEXP_API sexp sexp_9p_responderror (sexp ctx, sexp self, sexp_sint_t n, sexp req); +#else +SEXP_API sexp sexp_get_port_fileno (sexp ctx, sexp self, sexp_sint_t n, sexp port); #endif #if SEXP_USE_SIMPLIFY diff --git a/opcodes.c b/opcodes.c index b0bf7b70..659b8255 100644 --- a/opcodes.c +++ b/opcodes.c @@ -239,8 +239,10 @@ _FN2(_I(SEXP_OPCODE), _I(SEXP_TYPE), _I(SEXP_SYMBOL), "type-slot-offset", 0, sex _OP(SEXP_OPC_GETTER, SEXP_OP_SLOTN_REF, 3, 0, _I(SEXP_OBJECT), _I(SEXP_OBJECT), _I(SEXP_OBJECT), _I(SEXP_FIXNUM), 0, "slot-ref", 0, NULL), _OP(SEXP_OPC_SETTER, SEXP_OP_SLOTN_SET, 4, 0, SEXP_VOID, _I(SEXP_OBJECT), _I(SEXP_OBJECT), _I(SEXP_FIXNUM), 0,"slot-set!", 0, NULL), #endif -#if PLAN9 +#ifdef PLAN9 #include "opt/plan9-opcodes.c" +#else +_FN1(_I(SEXP_OBJECT), _I(SEXP_IPORT), "port-fileno", 0, sexp_get_port_fileno), #endif #if SEXP_USE_MODULES _FN0(_I(SEXP_ENV), "current-environment", 0, sexp_current_environment),