From b20a91d220a39b2defcf84fb042648fe17aa6112 Mon Sep 17 00:00:00 2001 From: roland Date: Tue, 5 Jul 1994 23:14:17 +0000 Subject: [PATCH] entered into RCS --- mach/devstream.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/mach/devstream.c b/mach/devstream.c index 43660a5076..9078c9288a 100644 --- a/mach/devstream.c +++ b/mach/devstream.c @@ -67,6 +67,7 @@ input (FILE *f) } +#if 0 static void output (FILE *f, int c) { @@ -123,10 +124,9 @@ output (FILE *f, int c) *f->__bufp++ = (unsigned char) c; } } +#endif - -#if 0 /* Translates \n to \r\n. */ static void output (FILE *f, int c) { @@ -216,18 +216,40 @@ output (FILE *f, int c) *f->__bufp++ = (unsigned char) c; } } -#endif + +static int +dealloc_ref (void *cookie) +{ + if (mach_port_deallocate (mach_task_self (), (mach_port_t) cookie)) + { + errno = EINVAL; + return -1; + } + return 0; +} + FILE * mach_open_devstream (mach_port_t dev, const char *mode) { - FILE *stream = fopencookie ((void *) dev, mode, __default_io_functions); + FILE *stream; + + if (mach_port_mod_refs (mach_task_self (), dev, MACH_PORT_RIGHT_SEND, 1)) + { + errno = EINVAL; + return NULL; + } + + stream = fopencookie ((void *) dev, mode, __default_io_functions); if (stream == NULL) - return NULL; + { + mach_port_deallocate (mach_task_self (), dev); + return NULL; + } stream->__room_funcs.__input = input; stream->__room_funcs.__output = output; - stream->__io_funcs.__close = (__io_close_fn *) device_close; + stream->__io_funcs.__close = dealloc_ref; stream->__io_funcs.__seek = NULL; /* Cannot seek. */ stream->__io_funcs.__fileno = NULL; /* No corresponding POSIX.1 fd. */ stream->__seen = 1; -- 2.11.0