#include <unistd.h>
#include <fcntl.h>
#include <stdhdrs.h>
#include <strbuf.h>
#include <error.h>
#include "pipe.h"
#include "err.h"
void Pipe::SetName( const char *pipename )
{
name.Set( pipename );
}
char *Pipe::GetName()
{
return name.Text();
}
int Pipe::GetIfd()
{
return ifd;
}
bool Pipe::Init( const char *pipename, Error *e )
{
SetName( pipename );
return true;
}
bool Pipe::Open( Error *e )
{
if( pipe( &ifd ) == -1 )
return syserr( "pipe", GetName(), e );
if( fcntl( ifd, F_SETFD, 1 ) == -1 )
return syserr( "ifd fcntl", GetName(), e );
if( fcntl( ofd, F_SETFD, 1 ) == -1 )
return syserr( "ofd fcntl", GetName(), e );
return true;
}
bool Pipe::Write( const void *buf, size_t count, Error *e )
{
if( write( ofd, buf, count ) == -1 )
return syserr( "write", GetName(), e );
return true;
}
bool Pipe::Close( Error *e )
{
if( close( ifd ) == -1 )
return syserr( "close input", GetName(), e );
if( close( ofd ) == -1 )
return syserr( "close output", GetName(), e );
return true;
}