Data Structures | Macros | Typedefs | Enumerations | Functions
gfsmIO.h File Reference

Abstract I/O routines. More...

#include <gfsmConfig.h>
#include <gfsmError.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
Include dependency graph for gfsmIO.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  gfsmIOHandle
 Generic I/O handle struct. More...
struct  gfsmPosGString
 GString with an associated index (read head) More...

Macros

#define GFSMIO_EOF   ((int)-1)

Typedefs

typedef void(* gfsmIOFlushFunc )(void *handle)
typedef void(* gfsmIOCloseFunc )(void *handle)
typedef gboolean(* gfsmIOEofFunc )(void *handle)
typedef gboolean(* gfsmIOReadFunc )(void *handle, void *buf, size_t nbytes)
typedef ssize_t(* gfsmIOGetdelimFunc )(void *handle, char **lineptr, size_t *n, int delim)
typedef gboolean(* gfsmIOWriteFunc )(void *handle, const void *buf, size_t nbytes)
typedef int(* gfsmIOVprintfFunc )(void *handle, const char *fmt, va_list *app)

Enumerations

enum  gfsmIOHandleType { gfsmIOTCFile, gfsmIOTZFile, gfsmIOTGString, gfsmIOTUser = 255 }

Functions

gfsmIOHandlegfsmio_handle_new (gfsmIOHandleType typ, void *handle_data)
void gfsmio_handle_free (gfsmIOHandle *ioh)
gfsmIOHandlegfsmio_new_file (FILE *f)
gfsmIOHandlegfsmio_new_zfile (FILE *f, const char *mode, int compress_level)
gfsmIOHandlegfsmio_new_filename (const char *filename, const char *mode, int compress_level, gfsmError **errp)
gfsmIOHandlegfsmio_new_gstring (gfsmPosGString *pgs)
void gfsmio_close (gfsmIOHandle *ioh)
void gfsmio_flush (gfsmIOHandle *ioh)
gboolean gfsmio_eof (gfsmIOHandle *ioh)
int gfsmio_getc (gfsmIOHandle *ioh)
gboolean gfsmio_read (gfsmIOHandle *ioh, void *buf, size_t nbytes)
ssize_t gfsmio_getline (gfsmIOHandle *ioh, char **lineptr, size_t *n)
ssize_t gfsmio_getdelim (gfsmIOHandle *io, char **lineptr, size_t *n, int delim)
gboolean gfsmio_putc (gfsmIOHandle *ioh, int c)
gboolean gfsmio_puts (gfsmIOHandle *io, const char *s)
gboolean gfsmio_write (gfsmIOHandle *io, const void *buf, size_t nbytes)
int gfsmio_printf (gfsmIOHandle *io, const char *fmt,...)
int gfsmio_vprintf (gfsmIOHandle *io, const char *fmt, va_list *app)

Detailed Description

Macro Definition Documentation

#define GFSMIO_EOF   ((int)-1)

Typedef Documentation

typedef void(* gfsmIOFlushFunc)(void *handle)

Generic I/O Handle function type: fflush() and friends

typedef void(* gfsmIOCloseFunc)(void *handle)

Generic I/O Handle function type: fclose() and friends

typedef gboolean(* gfsmIOEofFunc)(void *handle)

Generic I/O Handle function type: feof() and friends

typedef gboolean(* gfsmIOReadFunc)(void *handle, void *buf, size_t nbytes)

Generic I/O Handle function type: fread() and friends

typedef ssize_t(* gfsmIOGetdelimFunc)(void *handle, char **lineptr, size_t *n, int delim)

Generic I/O Handle function type: getdelim() and friends

typedef gboolean(* gfsmIOWriteFunc)(void *handle, const void *buf, size_t nbytes)

Generic I/O Handle function type: fwrite() and friends

typedef int(* gfsmIOVprintfFunc)(void *handle, const char *fmt, va_list *app)

Generic I/O Handle function type: vprintf() and friends

Enumeration Type Documentation

Builtin I/O types

Enumerator:
gfsmIOTCFile 

I/O on a C FILE*.

gfsmIOTZFile 

I/O on a zlib gzFile* (only if GFSM_ZLIB_ENABLED is defined)

gfsmIOTGString 

I/O on a GString*.

gfsmIOTUser 

user I/O

Function Documentation

gfsmIOHandle* gfsmio_handle_new ( gfsmIOHandleType  typ,
void *  handle_data 
)

create, initialize, and return a new gfsmIOHandle

Parameters
typtype of this handle
handle_datavalue of the handle structure datum:
  • for typ==gfsmIOTCFile , handle_data should be a FILE*
  • for typ==gfsmIOTGString , handle_data should be a gfsmPosGString*
  • for typ==gfsmIOTZFile , handle_data should be a gzFile
  • for typ==gfsmIOTUser , handle_data is whatever you want
Returns
new gfsmIOHandle
void gfsmio_handle_free ( gfsmIOHandle ioh)

destroy a gfsmIOHandle: does NOT implicitly call close or anything else

gfsmIOHandle* gfsmio_new_file ( FILE *  f)

Create and return a new gfsmIOHandle to an uncompressed C FILE* Caller is responsible for closing the handle.

gfsmIOHandle* gfsmio_new_zfile ( FILE *  f,
const char *  mode,
int  compress_level 
)

Create and return a new gfsmIOHandle to a C FILE* using compression (if available) Caller is responsible for closing the handle. The handle returned can always be closed without closing f itself.

gfsmIOHandle* gfsmio_new_filename ( const char *  filename,
const char *  mode,
int  compress_level,
gfsmError **  errp 
)

Create and return a new gfsmIOHandle to a named file. Uses gzFile if zlib support was enabled, otherwise C FILE* (uncompressed) Caller is responsible for closing the handle.

gfsmIOHandle* gfsmio_new_gstring ( gfsmPosGString pgs)

Create and return a new gfsmIOHandle for a PosGString* Caller is responsible for allocation and de-allocation of the PosGString*.

void gfsmio_close ( gfsmIOHandle ioh)

close an open I/O handle (calls close_func)

void gfsmio_flush ( gfsmIOHandle ioh)

flush all data to an output handle (calls flush_func)

gboolean gfsmio_eof ( gfsmIOHandle ioh)

returns true if h is at EOF, false otherwise (or if no eof_func is defined)

int gfsmio_getc ( gfsmIOHandle ioh)

read a single byte of data from h, should return GFSMIO_EOF on EOF

gboolean gfsmio_read ( gfsmIOHandle ioh,
void *  buf,
size_t  nbytes 
)

read nbytes of data from io into buf, as fread()

ssize_t gfsmio_getline ( gfsmIOHandle ioh,
char **  lineptr,
size_t *  n 
)

wrapper for getline(), returns number of bytes read (0 on error)

ssize_t gfsmio_getdelim ( gfsmIOHandle io,
char **  lineptr,
size_t *  n,
int  delim 
)

wrapper for getdelim(), returns number of bytes read (0 on error)

gboolean gfsmio_putc ( gfsmIOHandle ioh,
int  c 
)

write a single byte to handle ioh, as fputc()

gboolean gfsmio_puts ( gfsmIOHandle io,
const char *  s 
)

wrapper for puts()

gboolean gfsmio_write ( gfsmIOHandle io,
const void *  buf,
size_t  nbytes 
)

write nbytes of data from buf into io, as fwrite()

int gfsmio_printf ( gfsmIOHandle io,
const char *  fmt,
  ... 
)

wrapper for printf(): calls gfsmio_vprintf()

int gfsmio_vprintf ( gfsmIOHandle io,
const char *  fmt,
va_list *  app 
)

wrapper for vprintf(): calls vprintf_func