rtxFile.h File Reference

Common runtime functions for reading from or writing to files. More...

#include "rtxsrc/rtxContext.h"

Go to the source code of this file.

Functions

EXTERNRT OSBOOL rtxFileExists (const char *filePath)
 This function tests if a file exists.
EXTERNRT int rtxFileOpen (FILE **ppFile, const char *filePath, const char *access)
 This function opens a file for read, write, or append access.
EXTERNRT int rtxFileReadBinary (OSCTXT *pctxt, const char *filePath, OSOCTET **ppMsgBuf, size_t *pLength)
 This function reads the entire contents of a binary file into memory.
EXTERNRT int rtxFileReadText (OSCTXT *pctxt, const char *filePath, OSOCTET **ppMsgBuf, size_t *pLength)
 This function reads the entire contents of an ASCII text file into memory.
EXTERNRT int rtxFileWriteBinary (const char *filePath, const OSOCTET *pMsgBuf, size_t length)
 This function writes binary data from memory to the given file.
EXTERNRT int rtxFileWriteText (const char *filePath, const char *pMsgBuf)
 This function writes text data from memory to the given file.

Detailed Description

Common runtime functions for reading from or writing to files.

Definition in file rtxFile.h.


Function Documentation

EXTERNRT OSBOOL rtxFileExists ( const char *  filePath  ) 

This function tests if a file exists.

Parameters:
filePath Complete file path name of file to be tested.
Returns:
TRUE if file exists or FALSE if does not exist or some other error occurred.
EXTERNRT int rtxFileOpen ( FILE **  ppFile,
const char *  filePath,
const char *  access 
)

This function opens a file for read, write, or append access.

It is basically a wrapper for the C run-time fopen function except in the case of Visual Studio, the more secure fopen_s function is used.

Parameters:
ppFile Pointer to FILE variable to receive file pointer.
filePath Complete file path name of file to be opened.
access File access string as defined for C fopen.
Returns:
Completion status of operation:
  • 0 = success or negative status code.
EXTERNRT int rtxFileReadBinary ( OSCTXT pctxt,
const char *  filePath,
OSOCTET **  ppMsgBuf,
size_t *  pLength 
)

This function reads the entire contents of a binary file into memory.

A memory buffer is allocated for the file contents using the run-time memory management functions.

Parameters:
pctxt Pointer to context block structure.
filePath Complete file path name of file to read.
ppMsgBuf Pointer to message buffer to receive allocated memory pointer.
pLength Pointer to integer to receive length of data read.
Returns:
Completion status of operation:
  • 0 (ASN_OK) = success,
  • RTERR_FILNOTFOU = file not found
  • RTERR_FILEREAD = file read error (see errno)
EXTERNRT int rtxFileReadText ( OSCTXT pctxt,
const char *  filePath,
OSOCTET **  ppMsgBuf,
size_t *  pLength 
)

This function reads the entire contents of an ASCII text file into memory.

A memory buffer is allocated for the file contents using the run-time memory management functions. This function is identical to rtxReadFileBinary except that a) the file is opened in text mode, and b) and extra byte is allocated at the end for a null-terminator character.

Parameters:
pctxt Pointer to context block structure.
filePath Complete file path name of file to read.
ppMsgBuf Pointer to message buffer to receive allocated memory pointer.
pLength Pointer to integer to receive length of data read.
Returns:
Completion status of operation:
  • 0 (ASN_OK) = success,
  • RTERR_FILNOTFOU = file not found
  • RTERR_FILEREAD = file read error (see errno)
EXTERNRT int rtxFileWriteBinary ( const char *  filePath,
const OSOCTET *  pMsgBuf,
size_t  length 
)

This function writes binary data from memory to the given file.

Parameters:
filePath Complete file path name of file to be written to.
pMsgBuf Pointer to buffer containing data to be written.
length Size (in bytes) of data to be written
Returns:
Completion status of operation:
  • 0 = success,
  • negative status code if error
EXTERNRT int rtxFileWriteText ( const char *  filePath,
const char *  pMsgBuf 
)

This function writes text data from memory to the given file.

The text is expected to be terminated by a null terminator character. This function will work with standard ASCII or UTF-8 encoded text.

Parameters:
filePath Complete file path name of file to be written to.
pMsgBuf Pointer to buffer containing data to be written.
Returns:
Completion status of operation:
  • 0 = success,
  • negative status code if error