From a75b215fe3fd5e132fe290d6539a6e1e35e03c23 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Mon, 21 May 2012 12:52:27 +0200 Subject: [PATCH] Added fpipe(3) providing pipe(2) through the FILE interface. --- libmaxsi/Makefile | 1 + libmaxsi/fpipe.cpp | 37 +++++++++++++++++++++++++++++++++++++ libmaxsi/include/stdio.h | 1 + 3 files changed, 39 insertions(+) create mode 100644 libmaxsi/fpipe.cpp diff --git a/libmaxsi/Makefile b/libmaxsi/Makefile index 685fb617..3e6f3bb3 100644 --- a/libmaxsi/Makefile +++ b/libmaxsi/Makefile @@ -32,6 +32,7 @@ OBJS=\ ctype.o \ file.o \ fdio.o \ +fpipe.o \ stdio.o \ dir.o \ fddir-sortix.o \ diff --git a/libmaxsi/fpipe.cpp b/libmaxsi/fpipe.cpp new file mode 100644 index 00000000..635c4ba9 --- /dev/null +++ b/libmaxsi/fpipe.cpp @@ -0,0 +1,37 @@ +/****************************************************************************** + + COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + fpipe.cpp + Provides pipe(2) through the FILE interface. + +*******************************************************************************/ + +#include +#include + +extern "C" int fpipe(FILE* pipes[2]) +{ + int pipefd[2]; + if ( pipe(pipefd) ) { return -1; } + pipes[0] = fdopen(pipefd[0], "r"); + if ( !pipes[0] ) { close(pipefd[0]); close(pipefd[1]); return -1; } + pipes[1] = fdopen(pipefd[1], "w"); + if ( !pipes[1] ) { fclose(pipes[0]); close(pipefd[1]); return -1; } + return 0; +} diff --git a/libmaxsi/include/stdio.h b/libmaxsi/include/stdio.h index d06afc74..31276c8c 100644 --- a/libmaxsi/include/stdio.h +++ b/libmaxsi/include/stdio.h @@ -164,6 +164,7 @@ void fregister(FILE* fp); void funregister(FILE* fp); FILE* fnewfile(void); int fcloseall(void); +int fpipe(FILE* pipes[2]); #endif #if __SORTIX_STDLIB_REDIRECTS