XBinder  Version 2.6.x
Functions
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. More...
 
EXTERNRT OSBOOL rtxFileIsDirectory (const char *filePath)
 This function tests if a file is actually a directory. More...
 
EXTERNRT time_t rtxFileLastModified (const char *filePath)
 This function returns the last modified time for a given file. More...
 
EXTERNRT int rtxFileOpen (FILE **ppFile, const char *filePath, const char *access)
 This function opens a file for read, write, or append access. More...
 
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. More...
 
EXTERNRT int rtxFileReadBinary2 (OSCTXT *pctxt, FILE *pFile, OSOCTET **ppMsgBuf, size_t *pLength)
 This function reads the entire contents of a binary file into memory. More...
 
EXTERNRT int rtxFileReadBinToSysMem (OSCTXT *pctxt, const char *filePath, OSOCTET **ppMsgBuf, size_t *pLength)
 This function reads the entire contents of a binary file into memory. More...
 
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. More...
 
EXTERNRT int rtxFileWriteBinary (const char *filePath, const OSOCTET *pMsgBuf, size_t length)
 This function writes binary data from memory to the given file. More...
 
EXTERNRT int rtxFileWriteText (const char *filePath, const char *pMsgBuf)
 This function writes text data from memory to the given file. More...
 
EXTERNRT int rtxFileCopyTextFile (const char *srcFilePath, const char *destFilePath)
 This function copies the contents on one text file to another. More...
 

Detailed Description

Common runtime functions for reading from or writing to files.

Definition in file rtxFile.h.

Function Documentation

◆ rtxFileCopyTextFile()

EXTERNRT int rtxFileCopyTextFile ( const char *  srcFilePath,
const char *  destFilePath 
)

This function copies the contents on one text file to another.

Parameters
srcFilePathComplete file path name of file to be copied.
destFilePathComplete file path name of target file.
Returns
Completion status of operation:
  • 0 (ASN_OK) = success,
  • RTERR_FILNOTFOU = source file not found
  • RTERR_FILEREAD = file read error (see errno)

◆ rtxFileExists()

EXTERNRT OSBOOL rtxFileExists ( const char *  filePath)

This function tests if a file exists.

Parameters
filePathComplete file path name of file to be tested.
Returns
TRUE if file exists or FALSE if does not exist or some other error occurred.

◆ rtxFileIsDirectory()

EXTERNRT OSBOOL rtxFileIsDirectory ( const char *  filePath)

This function tests if a file is actually a directory.

Parameters
filePathComplete path name of file to be tested.
Returns
TRUE if file is a directory or FALSE otherwise (including if the file doesn't exist).

◆ rtxFileLastModified()

EXTERNRT time_t rtxFileLastModified ( const char *  filePath)

This function returns the last modified time for a given file.

If the file does not exist or some error occurs, 0 is returned.

◆ rtxFileOpen()

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
ppFilePointer to FILE variable to receive file pointer.
filePathComplete file path name of file to be opened.
accessFile access string as defined for C fopen.
Returns
Completion status of operation:
  • 0 = success or negative status code.

◆ rtxFileReadBinary()

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
pctxtPointer to context block structure.
filePathComplete file path name of file to read.
ppMsgBufPointer to message buffer to receive allocated memory pointer.
pLengthPointer 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)

◆ rtxFileReadBinary2()

EXTERNRT int rtxFileReadBinary2 ( OSCTXT pctxt,
FILE *  pFile,
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
pctxtPointer to context block structure.
pFilePointer to the open file.
ppMsgBufPointer to message buffer to receive allocated memory pointer.
pLengthPointer 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)

◆ rtxFileReadBinToSysMem()

EXTERNRT int rtxFileReadBinToSysMem ( 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 standard configured system memory allocation function (usually malloc).

Parameters
pctxtPointer to context block structure.
filePathComplete file path name of file to read.
ppMsgBufPointer to message buffer to receive allocated memory pointer.
pLengthPointer 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)

◆ rtxFileReadText()

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
pctxtPointer to context block structure.
filePathComplete file path name of file to read.
ppMsgBufPointer to message buffer to receive allocated memory pointer.
pLengthPointer 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)

◆ rtxFileWriteBinary()

EXTERNRT int rtxFileWriteBinary ( const char *  filePath,
const OSOCTET *  pMsgBuf,
size_t  length 
)

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

Parameters
filePathComplete file path name of file to be written to.
pMsgBufPointer to buffer containing data to be written.
lengthSize (in bytes) of data to be written
Returns
Completion status of operation:
  • 0 = success,
  • negative status code if error

◆ rtxFileWriteText()

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
filePathComplete file path name of file to be written to.
pMsgBufPointer to buffer containing data to be written.
Returns
Completion status of operation:
  • 0 = success,
  • negative status code if error