File: sioStdio.c

package info (click to toggle)
ted 2.16-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,944 kB
  • ctags: 20,273
  • sloc: ansic: 167,980; makefile: 12,518; sh: 263
file content (65 lines) | stat: -rw-r--r-- 1,678 bytes parent folder | download | duplicates (2)
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
/************************************************************************/
/*									*/
/*  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, 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;
    }