1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
/************************************************************************/
/* */
/* Simple io streams: Duplicate the stream to another one: Usually */
/* for debugging putposes. */
/* */
/************************************************************************/
# include "appUtilConfig.h"
# include <stdlib.h>
# include "sioFork.h"
# include <appDebugon.h>
/************************************************************************/
/* */
/* Exchange of hexed binary little endian data. */
/* */
/************************************************************************/
static int sioForkClose( void * voids )
{
if ( voids )
{ free( voids ); }
return 0;
}
typedef struct ForkedInputStream
{
SimpleInputStream * fisSisIn;
SimpleOutputStream * fisSosFork;
int fisExhausted;
} ForkedInputStream;
static int sioInForkReadBytes( void * voidfis,
unsigned char * buffer,
int count )
{
ForkedInputStream * fis= (ForkedInputStream *)voidfis;
int done= 0;
if ( fis->fisExhausted )
{ LDEB(fis->fisExhausted); return -1; }
while( done < count )
{
int got;
got= sioInReadBytes( fis->fisSisIn, buffer, count- done );
if ( got <= 0 )
{ fis->fisExhausted= 1; break; }
sioOutWriteBytes( fis->fisSosFork, buffer, got );
done += got;
buffer += got;
}
return done;
}
SimpleInputStream * sioInForkOpen( SimpleInputStream * sisIn,
SimpleOutputStream * sosFork )
{
SimpleInputStream * sis;
ForkedInputStream * fis;
fis= malloc( sizeof(ForkedInputStream) );
if ( ! fis )
{ XDEB(fis); return (SimpleInputStream *)0; }
fis->fisSisIn= sisIn;
fis->fisSosFork= sosFork;
fis->fisExhausted= 0;
sis= sioInOpen( (void *)fis,
sioInForkReadBytes, (SIOinSEEK)0, sioForkClose );
if ( ! sis )
{ XDEB(sis); free( fis ); return (SimpleInputStream *)0; }
return sis;
}
/************************************************************************/
/* */
/************************************************************************/
typedef struct ForkedOutputStream
{
SimpleOutputStream * fosSosOut;
SimpleOutputStream * fosSosFork;
} ForkedOutputStream;
static int sioOutForkWriteBytes( void * voidfos,
const unsigned char * buffer,
int count )
{
ForkedOutputStream * fos= (ForkedOutputStream *)voidfos;
sioOutWriteBytes( fos->fosSosFork, buffer, count );
return sioOutWriteBytes( fos->fosSosOut, buffer, count );
}
SimpleOutputStream * sioOutForkOpen( SimpleOutputStream * sosOut,
SimpleOutputStream * sosFork )
{
SimpleOutputStream * sos;
ForkedOutputStream * fos;
fos= malloc( sizeof(ForkedInputStream) );
if ( ! fos )
{ XDEB(fos); return (SimpleOutputStream *)0; }
fos->fosSosOut= sosOut;
fos->fosSosFork= sosFork;
sos= sioOutOpen( (void *)fos, sioOutForkWriteBytes,
(SIOoutSEEK)0, sioForkClose );
if ( ! sos )
{ XDEB(sos); free( fos ); return (SimpleOutputStream *)0; }
return sos;
}
|