libopc
Data Structures | Macros | Typedefs | Enumerations | Functions
file.h File Reference
#include <opc/config.h>

Go to the source code of this file.

Data Structures

struct  OPC_FILERAWSTATE_STRUCT
 
struct  OPC_IO_STRUCT
 

Macros

#define OPC_FILE_READ
 
#define OPC_FILE_WRITE
 
#define OPC_FILE_TRUNC
 

Typedefs

typedef enum OPC_FILESEEKMODE_ENUM opcFileSeekMode
 
typedef int opcFileReadCallback(void *iocontext, char *buffer, int len)
 
typedef int opcFileWriteCallback(void *iocontext, const char *buffer, int len)
 
typedef int opcFileCloseCallback(void *iocontext)
 
typedef opc_ofs_t opcFileSeekCallback(void *iocontext, opc_ofs_t ofs)
 
typedef int opcFileTrimCallback(void *iocontext, opc_ofs_t new_size)
 
typedef int opcFileFlushCallback(void *iocontext)
 
typedef struct OPC_FILERAWSTATE_STRUCT opcFileRawState
 
typedef struct OPC_IO_STRUCT opcIO_t
 

Enumerations

enum  OPC_FILESEEKMODE_ENUM { opcFileSeekSet = SEEK_SET, opcFileSeekCur = SEEK_CUR, opcFileSeekEnd = SEEK_END }
 

Functions

opc_error_t opcFileInitIO (opcIO_t *io, opcFileReadCallback *ioread, opcFileWriteCallback *iowrite, opcFileCloseCallback *ioclose, opcFileSeekCallback *ioseek, opcFileTrimCallback *iotrim, opcFileFlushCallback *ioflush, void *iocontext, pofs_t file_size, int flags)
 
opc_error_t opcFileInitIOFile (opcIO_t *io, const xmlChar *filename, int flags)
 
opc_error_t opcFileInitIOMemory (opcIO_t *io, const opc_uint8_t *data, opc_uint32_t data_len, int flags)
 
opc_error_t opcFileCleanupIO (opcIO_t *io)
 

Detailed Description

The opc module contains the file library functions.

Macro Definition Documentation

#define OPC_FILE_READ

Flag for READ access.

Examples:
opc_zipextract.c, opc_zipread.c, and opc_zipwrite.c.
#define OPC_FILE_TRUNC

Flag indicates that file will be truncated when opened.

#define OPC_FILE_WRITE

Flag for WRITE access.

Examples:
opc_zipwrite.c.

Typedef Documentation

typedef int opcFileCloseCallback(void *iocontext)

Callback to close a file. E.g. for a FILE * context this can be implemented as

1 static int opcFileClose(void *iocontext) {
2  return fclose((FILE*)iocontext);
3 }
typedef int opcFileFlushCallback(void *iocontext)

Callback to flush a file. E.g. for a FILE * context this can be implemented as

1 static int opcFileFlush(void *iocontext) {
2  return fflush((FILE*)iocontext);
3 }

Represents a state of a file, i.e. file position (buf_pos) and error status (err).

typedef int opcFileReadCallback(void *iocontext, char *buffer, int len)

Callback to read a file. E.g. for a FILE * context this can be implemented as

1 static int opcFileRead(void *iocontext, char *buffer, int len) {
2  return fread(buffer, sizeof(char), len, (FILE*)iocontext);
3 }
typedef opc_ofs_t opcFileSeekCallback(void *iocontext, opc_ofs_t ofs)

Callback to seek a file. E.g. for a FILE * context this can be implemented as

1 static opc_ofs_t opcFileSeek(void *iocontext, opc_ofs_t ofs) {
2  int ret=fseek((FILE*)iocontext, ofs, SEEK_SET);
3  if (ret>=0) {
4  return ftell((FILE*)iocontext);
5  } else {
6  return ret;
7  }
8 }

Abstraction for see modes.

typedef int opcFileTrimCallback(void *iocontext, opc_ofs_t new_size)

Callback to trim a file. E.g. for a FILE * context this can be implemented as

1 static int opcFileTrim(void *iocontext, opc_ofs_t new_size) {
2 #ifdef WIN32
3  return _chsize(fileno((FILE*)iocontext), new_size);
4 #else
5  return ftruncate(fileno((FILE*)iocontext), new_size);
6 #endif
7 }
typedef int opcFileWriteCallback(void *iocontext, const char *buffer, int len)

Callback to write a file. E.g. for a FILE * context this can be implemented as

1 static int opcFileWrite(void *iocontext, const char *buffer, int len) {
2  return fwrite(buffer, sizeof(char), len, (FILE*)iocontext);
3 }
typedef struct OPC_IO_STRUCT opcIO_t

File IO context.

Enumeration Type Documentation

Abstraction for see modes.

Function Documentation

opc_error_t opcFileCleanupIO ( opcIO_t io)

Cleanup an IO context, i.e. release all system resources.

Examples:
opc_zipextract.c, opc_zipread.c, and opc_zipwrite.c.
opc_error_t opcFileInitIO ( opcIO_t io,
opcFileReadCallback ioread,
opcFileWriteCallback iowrite,
opcFileCloseCallback ioclose,
opcFileSeekCallback ioseek,
opcFileTrimCallback iotrim,
opcFileFlushCallback ioflush,
void *  iocontext,
pofs_t  file_size,
int  flags 
)

Initialize an IO context.

opc_error_t opcFileInitIOFile ( opcIO_t io,
const xmlChar *  filename,
int  flags 
)

Initialize an IO context for a file.

Examples:
opc_zipextract.c, opc_zipread.c, and opc_zipwrite.c.
opc_error_t opcFileInitIOMemory ( opcIO_t io,
const opc_uint8_t data,
opc_uint32_t  data_len,
int  flags 
)

Initialize an IO for memory.

Warning
Currently supports READ-ONLY file access.