Beispiel #1
0
/*****************************************************************************
 * FUNCTION - ReadString
 * DESCRIPTION: IFlashReader implementation
 * NOTICE: szValue buffer must be large enough to hold maxLen + 1 chars!
 ****************************************************************************/
void FlashBlock::ReadString(char* szValue, int maxLen, const char* szDefaultValue)
{
  int flashLen, flashMaxLen;

  if (CanRead(8))
  {
    flashLen = ReadI32(0);    // string length stored in flash
    flashMaxLen = ReadI32(0); // max string length in flash

    if (CanRead(flashMaxLen))
    {
      if (flashLen <= maxLen)
      {
        memcpy(szValue, mpBlockData + mReadPos, flashLen);
        szValue[flashLen] = '\0';
      }
      else  // string stored in flash to long, use default
      {
        strncpy(szValue, szDefaultValue, maxLen);
        szValue[maxLen] = '\0';
      }

      mReadPos += flashMaxLen;
      mReadAvailable -= flashMaxLen;
    }
    else  // not enough data
    {
      strncpy(szValue, szDefaultValue, maxLen);
      szValue[maxLen] = '\0';
    }
  }
  else // not enough data
  {
    strncpy(szValue, szDefaultValue, maxLen);
    szValue[maxLen] = '\0';
  }
}
Beispiel #2
0
bool MmapFile::ReadUI32(uint32_t *pValue, bool networkOrder) {
	return ReadI32((int32_t *) pValue, networkOrder);
}