Main Page   Modules   Alphabetical List   Compound List   File List   Compound Members   File Members  

PSStream

Generic stream I/O. More...

Compounds

struct  psStream
struct  psStreamFuncs

Functions

PSStreamFuncspsStreamFuncsAlloc (void)
 Allocates and initializes a PSStreamFuncs structure. More...

void psStreamFuncsFree (PSStreamFuncs *funcs)
 Frees a PSStreamFuncs structure. More...

PSStream* psStreamAlloc (void* stream, PSStreamFuncs* funcs)
 Allocates and initializes a PSStream structure. More...

void psStreamFree (PSStream *str)
 Frees a PSStream structure. More...

size_t psRead (void* ptr, size_t size, size_t nmemb, PSStream* str)
 Read size * nmemb bytes from the stream referenced by str into the buffer ptr. More...

size_t psWrite (const void* ptr, size_t size, size_t nmemb, PSStream* str)
 Writes size * nmemb bytes to the stream referenced by str from the buffer ptr. More...

long psTell (PSStream* str)
 Obtains the current postion in the stream referenced by str. More...

int psSeek (PSStream* str, long offset, int whence)
 Sets the current position for the stream referenced by str. More...

int psGetC (PSStream* str)
 Reads the next character from the stream referenced by str. More...

int psUngetC (int c, PSStream* str)
 Pushes c back to the stream referenced by str. More...

int psPutC (int c, PSStream* str)
 Puts c to the stream referenced by str. More...

char* psGetS (char* s, int size, PSStream* str)
 Reads a line from the stream referenced by str. More...

int psPutS (char* s, PSStream* str)
 Writes the string s to the stream referenced by str. More...

int psEof (PSStream* str)
 Tests for the end of file condition of the stream referenced by str. More...

int psPrintf (PSStream* str, char *format, ...)
 Output formatted data to the stream referenced by str. More...


Variables

PSStreamFuncs psStandardStreamFuncs
 Standard I/O PSStream. More...


Detailed Description

Generic stream I/O.

This module contains generic stream I/O routines which are used to generalize read/writing etc. to support use of "streams" besides normal files (such as memory streams, compressed archives, etc.)

To use these routines allocate a PSStreamFuncs structure using psStreamFuncsAlloc() and fill in the read, write, and optionally the tell and seek members with pointers to your functions to handle the stream I/O. These functions should function the same as the Standard C Library fread(), fwrite(), ftell() and fseek(). Notice that these functions are passed a void * (stream) which can be used by your routines to store information about the real stream.

Next allocate a PSStream structure using psStreamAlloc().

Then use the various functions to read/write/whatever then free the PSStream structure with psStreamFree().

The I/O functions in this file function (or should) the same as their counterparts in the Standard C Library.


Function Documentation

int psEof ( PSStream * str )
 

Tests for the end of file condition of the stream referenced by str.

Equivalent to the Standard C Library function feof().

Parameters:
str   pointer to PSStream.

Returns:
a non-zero value if the stream is at end of file and 0 if not.

int psGetC ( PSStream * str )
 

Reads the next character from the stream referenced by str.

Equivalent to the Standard C Library function fgetc().

Parameters:
str   pointer to PSStream.

Returns:
the next character on success or EOF on end of file or an error.

char * psGetS ( char * s,
int size,
PSStream * str )
 

Reads a line from the stream referenced by str.

Reads in at most size characters and stores them into the buffer pointed to by s. Reading stops after either EOF or a newline. If a newline is read, it is stored in the buffer. The buffer is null terminated. Equivalent to the Standard C Library function fgets().

Parameters:
s   pointer to buffer.
size   maximum number of characters to read.
str   pointer to PSStream.

Returns:
s on success or NULL on end of file or an error.

int psPrintf ( PSStream * str,
char * format,
... )
 

Output formatted data to the stream referenced by str.

Equivalent to the Standard C Library function fprintf().

Parameters:
str   pointer to PSStream.
format   printf() like format string.

Returns:
the number of characters written.

int psPutC ( int c,
PSStream * str )
 

Puts c to the stream referenced by str.

Equivalent to the Standard C Library function fputc().

Parameters:
c   character to be output.
str   pointer to PSStream.

Returns:
c on success or EOF on error.

int psPutS ( char * s,
PSStream * str )
 

Writes the string s to the stream referenced by str.

Does not write the null terminator and does not append a newline. Equivalent to the Standard C Library function fputs().

Parameters:
s   pointer to string to output.
str   pointer to PSStream.

Returns:
a non-negative number on success or EOF on failure.

size_t psRead ( void * ptr,
size_t size,
size_t nmemb,
PSStream * str )
 

Read size * nmemb bytes from the stream referenced by str into the buffer ptr.

Equivalent to the Standard C Library fread() function.

Parameters:
ptr   pointer to buffer.
size   size of each element.
nmemb   number of elements to read.
str   pointer to PSStream.

Returns:
number of bytes written.

int psSeek ( PSStream * str,
long offset,
int whence )
 

Sets the current position for the stream referenced by str.

Equivalent to the Standard C Library function fseek().

Parameters:
str   pointer to PSStream.
offset   the new position.
whence   either SEEK_SET, SEEK_CUR, or SEEK_END.

Returns:
0 on success or -1 on failure.

PSStream * psStreamAlloc ( void * stream,
PSStreamFuncs * funcs )
 

Allocates and initializes a PSStream structure.

Returns:
A pointer to the newly allocated structure on success or NULL on failure.

void psStreamFree ( PSStream * str )
 

Frees a PSStream structure.

Parameters:
str   pointer to PSStream structure to be freed.

Returns:
nothing.

PSStreamFuncs * psStreamFuncsAlloc ( void )
 

Allocates and initializes a PSStreamFuncs structure.

Returns:
A pointer to the newly allocated structure on success or NULL on failure.

void psStreamFuncsFree ( PSStreamFuncs * funcs )
 

Frees a PSStreamFuncs structure.

Parameters:
funcs   pointer to PSStreamFuncs structure to be freed.

Returns:
nothing.

long psTell ( PSStream * str )
 

Obtains the current postion in the stream referenced by str.

Equivalent to the Standard C Library function ftell().

Parameters:
str   pointer to PSStream.

Returns:
the current position in the stream on success or -1 on failure.

int psUngetC ( int c,
PSStream * str )
 

Pushes c back to the stream referenced by str.

Equivalent to the Standard C Library function ungetc(). Currently only supports one characater.

Parameters:
c   character to be pushed back.
str   pointer to PSStream.

Returns:
c on success or EOF on failure.

size_t psWrite ( const void * ptr,
size_t size,
size_t nmemb,
PSStream * str )
 

Writes size * nmemb bytes to the stream referenced by str from the buffer ptr.

Equivalent to the Standard C Library fwrite() function.

Parameters:
ptr   pointer to buffer.
size   size of each element.
nmemb   number of elements to write.
str   pointer to PSStream.

Returns:
number of bytes written.


Variable Documentation

PSStreamFuncs psStandardStreamFuncs
 

Initializer:

{
    (psFileRead)fread,          
    (psFileWrite)fwrite,        
    (psFileTell)ftell,          
    (psFileSeek)fseek
  }
Standard I/O PSStream.

This is a PSStreamFuncs structure utilizing standard buffered file I/O routines (fread, fwrite, etc.) that is defined here as a convience.


Generated at Mon Dec 11 22:46:31 2000 for Postscript Utility Library by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000