head 1.3; access; symbols SFIO_1999:1.1.1.2 SFIO_1998:1.1.1.1 ATT:1.1.1; locks; strict; comment @ * @; 1.3 date 99.09.11.13.20.42; author rse; state Exp; branches; next 1.2; 1.2 date 99.09.11.12.42.09; author rse; state Exp; branches; next 1.1; 1.1 date 98.03.19.03.58.13; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 98.03.19.03.58.13; author rse; state Exp; branches; next 1.1.1.2; 1.1.1.2 date 99.06.01.15.22.34; author rse; state Exp; branches; next ; desc @@ 1.3 log @Merge in Sfio 1999 changes @ text @#include "sfdchdr.h" /* A discipline to tee the output to a stream to another stream. ** This is similar to what the "tee" program does. As implemented ** this discipline only works with file streams. ** ** Written by Kiem-Phong Vo, kpv@@research.att.com, 03/18/1998. */ /* the discipline structure for tee-ing */ typedef struct _tee_s { Sfdisc_t disc; /* the sfio discipline structure */ Sfio_t* tee; /* the stream to tee to */ int status; /* if tee stream is still ok */ } Tee_t; /* write to the teed stream. */ #if __STD_C static ssize_t teewrite(Sfio_t* f, const Void_t* buf, size_t size, Sfdisc_t* disc) #else static ssize_t teewrite(f,buf,size,disc) Sfio_t* f; /* the stream being written to */ Void_t* buf; /* the buffer of data being output */ size_t size; /* the data size */ Sfdisc_t* disc; /* the tee discipline */ #endif { reg Tee_t* te = (Tee_t*)disc; /* tee data if still ok */ if(te->status == 0 && sfwrite(te->tee,buf,size) != (ssize_t)size) te->status = -1; /* do the actual write */ return sfwr(f,buf,size,disc); } /* on close, remove the discipline */ #if __STD_C static int teeexcept(Sfio_t* f, int type, Void_t* data, Sfdisc_t* disc) #else static int teeexcept(f,type,data,disc) Sfio_t* f; int type; Void_t* data; Sfdisc_t* disc; #endif { if(type == SF_FINAL || type == SF_DPOP) free(disc); return 0; } #if __STD_C int sfdctee(Sfio_t* f, Sfio_t* tee) #else int sfdctee(f, tee) Sfio_t* f; /* stream to tee from */ Sfio_t* tee; /* stream to tee to */ #endif { reg Tee_t* te; if(!(te = (Tee_t*)malloc(sizeof(Tee_t))) ) return -1; te->disc.readf = NIL(Sfread_f); te->disc.seekf = NIL(Sfseek_f); te->disc.writef = teewrite; te->disc.exceptf = teeexcept; te->tee = tee; te->status = 0; if(sfdisc(f,(Sfdisc_t*)te) != (Sfdisc_t*)te) { free(te); return -1; } return 0; } @ 1.2 log @Incorporate stuff from RSE's Sfio98 variant @ text @d31 1 a31 1 if(te->status == 0 && sfwrite(te->tee,buf,size) != size) @ 1.1 log @Initial revision @ text @d40 1 a40 1 static teeexcept(Sfio_t* f, int type, Void_t* data, Sfdisc_t* disc) d42 1 a42 1 static teeexcept(f,type,data,disc) @ 1.1.1.1 log @Import of Sfio1998 @ text @@ 1.1.1.2 log @Import of Sfio1999 @ text @d31 1 a31 1 if(te->status == 0 && sfwrite(te->tee,buf,size) != (ssize_t)size) @