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
|
/************************************************************************/
/* */
/* Simple io streams using the C stdio. */
/* */
/************************************************************************/
# include "appUtilConfig.h"
# include <sioStdio.h>
# include <appDebugoff.h>
static int sioStdioClose( void * voidf )
{ return fclose( (FILE *)voidf ); }
static int sioStdioSeek( void * voidf,
long pos )
{
if ( fseek( (FILE *)voidf, pos, SEEK_SET ) )
{ LDEB(pos); return -1; }
return 0;
}
static int sioInStdioReadBytes( void * voidf,
unsigned char * buffer,
int count )
{ return fread( buffer, 1, count, (FILE *)voidf ); }
SimpleInputStream * sioInStdioOpen( const char * filename )
{
SimpleInputStream * sis;
FILE * f= fopen( filename, "rb" );
if ( ! f )
{ SXDEB(filename,f); return (SimpleInputStream *)0; }
sis= sioInOpen( (void *)f,
sioInStdioReadBytes, sioStdioSeek, sioStdioClose );
if ( ! sis )
{ SXDEB(filename,sis); fclose( f ); return (SimpleInputStream *)0; }
return sis;
}
static int sioOutStdioWriteBytes( void * voidf,
const unsigned char * buffer,
int count )
{ return fwrite( buffer, 1, count, (FILE *)voidf ); }
SimpleOutputStream * sioOutStdioOpen( const char * filename )
{
SimpleOutputStream * sos;
FILE * f= fopen( filename, "w" );
if ( ! f )
{ SXDEB(filename,f); return (SimpleOutputStream *)0; }
sos= sioOutOpen( (void *)f, sioOutStdioWriteBytes,
sioStdioSeek, sioStdioClose );
if ( ! sos )
{ SXDEB(filename,sos); fclose( f ); return (SimpleOutputStream *)0; }
return sos;
}
|