aFile.h

group aFile

Platform Independent File Access Interface.

aFile.h provides a platform independent interface for opening, reading, and writing files.

typedef void *aFileRef

Typedef aFileRef Opaque reference to a file handle.

enum aFileMode

Enum aFileMode.

Represents whether the file is to be opened in read or write mode.

Values:

aFileModeReadOnly

File read mode.

aFileModeWriteOnly

File write mode.

aFileModeAppend

File write mode from end of current file.

aFileModeUnknown

File in unknown mode.

enum aFileSeekMode

Enum aFileSeekMode.

Represents the seek start location.

Values:

aSeekStart

Perform a seek from the beginning of the file.

aSeekCurrent

Perform a seek from the current location.

aSeekEnd

Perform a seek from the end of the file.

bool aFile_Exists(const char *pFilename)

Does the File Exist.

Checks for the existence of a file at filename.

Return
bool True if file exists, false otherwise.
Parameters
  • pFilename: path to file.

aFileRef aFile_Open(const char *pFilename, const aFileMode eMode)

Open a File.

Opens the file Given in pFilename with the given fileMode eMode.

Return
aFileRef on success or NULL on failure.
Parameters
  • pFilename: path to file.
  • eMode: Open the file for Reading or Writing.

aErr aFile_Close(aFileRef *fileRef)

Close an open file.

Close an open file. The fileRef is set to NULL on success.

Return
Function returns aErr values.
Parameters
  • fileRef: Pointer to the handle to the open file.
Return Value
  • aErrNone: Success.
  • aErrParam: invalid file reference.

aErr aFile_Read(aFileRef fileRef, uint8_t *pBuffer, const size_t nLength, size_t *pActuallyRead)

Read from an open file.

Read from an open file.

Return
Function returns aErr values.
Parameters
  • fileRef: The handle to the open file.
  • pBuffer: The data buffer to read into.
  • nLength: The length of the read buffer.
  • pActuallyRead: The Number of bytes actually read from the file.
Return Value
  • aErrNone: Success.
  • aErrMode: The file is not readable.
  • aErrIO: An error occured reading from the file.
  • aErrEOF: Read reached the end of the file.

aErr aFile_Write(aFileRef fileRef, const uint8_t *pBuffer, const size_t nLength, size_t *pActuallyWritten)

Write to an open file.

Write to an open file.

Return
Function returns aErr values.
Parameters
  • fileRef: The handle to the open file.
  • pBuffer: The data to write.
  • nLength: The length of the data to write.
  • pActuallyWritten: The Number of bytes actually written to the file.
Return Value
  • aErrNone: Success.
  • aErrMode: The file is not writable.
  • aErrIO: An error occured writing to the file.

aErr aFile_Seek(aFileRef fileRef, const long nOffset, aFileSeekMode seekFrom)

Seek within an open file.

Seek within an open file.

Return
Function returns aErr values.
Parameters
  • fileRef: The handle to the open file.
  • nOffset: The number of bytes to move within the file.
  • seekFrom: The location to begin the seek from.
Return Value
  • aErrNone: Success.
  • aErrEOF: Seek would run off the end of the file.
  • aErrRange: Seek would run off the beginning of the file.
  • aErrIO: An error occured moving the file pointer.

aErr aFile_GetSize(aFileRef fileRef, size_t *pulSize)

Get the size of an open file.

Get the size of an open file.

Return
Function returns aErr values.
Parameters
  • fileRef: The handle to the open file.
  • pulSize: Out param filled with the size of the open file.
Return Value
  • aErrNone: Success.
  • aErrParam: the fileRef is invalid.
  • aErrIO: an error occured calculating the size.

aErr aFile_Delete(const char *pFilename)

Delete a File.

Deletes the given file pFilename.

Return
Function returns aErr values.
Parameters
  • pFilename: Path to file.
Return Value
  • aErrNone: Success.
  • aErrPermission: user has insufficient priviledges.
  • aErrNotFound: if the file cannot be located.