Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save danwalmsley/5e9d4498aa2b024e1bd9769ece454061 to your computer and use it in GitHub Desktop.
Save danwalmsley/5e9d4498aa2b024e1bd9769ece454061 to your computer and use it in GitHub Desktop.
/******************************************************************************
* Description:
*
* Author:
* Date: 16 November 2016
*
*******************************************************************************/
#pragma mark Compiler Pragmas
#pragma mark Includes
#include "Gateway164File.h"
#include "Gateway164FileSystem.h"
extern "C" {
#include "m2m_fs_api.h"
}
#pragma mark Definitions and Constants
#pragma mark Static Data
#pragma mark Static Functions
#pragma mark Member Implementations
IFile& Gateway164FileSystem::OpenFile (const char* fileName, FileMode mode)
{
M2M_T_FS_HANDLE handle = nullptr;
switch (mode)
{
case FileMode::Create:
handle = m2m_fs_open (const_cast<CHAR*> (fileName), M2M_FS_OPEN_CREATE);
break;
default:
case FileMode::Read:
handle = m2m_fs_open (const_cast<CHAR*> (fileName), M2M_FS_OPEN_READ);
break;
}
return *new Gateway164File (handle);
}
IFile& Gateway164FileSystem::CreateFile (const char* fileName)
{
m2m_fs_create (const_cast<CHAR*> (fileName));
return OpenFile (fileName, FileMode::Create);
}
bool Gateway164FileSystem::Exists (const char* fileName)
{
bool result = false;
auto handle = m2m_fs_open (const_cast<CHAR*> (fileName), M2M_FS_OPEN_READ);
if (handle != static_cast<void*> (NULL))
{
m2m_fs_close (handle);
result = true;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment