~haggai-eran/nux/rtl-rebased

« back to all changes in this revision

Viewing changes to NuxCore/CRC32.cpp

  • Committer: Jay Taoko
  • Date: 2011-10-21 23:49:15 UTC
  • mfrom: (508.1.2 nux-20)
  • Revision ID: jay.taoko@canonical.com-20111021234915-hnzakb5ndebica8i
* Removed custom Nux types: t_u32, t_s32, t_bool, ...

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
128
128
// Reflection is a requirement for the official CRC-32 standard.
129
129
//      You can create CRCs without it, but they won't conform to the standard.
130
 
  t_u32 CRC32::Reflect (t_u32 ulReflect, char cChar)
 
130
  unsigned int CRC32::Reflect (unsigned int ulReflect, char cChar)
131
131
  {
132
 
    t_u32 ulValue = 0;
 
132
    unsigned int ulValue = 0;
133
133
 
134
134
    // Swap bit 0 for bit 7 bit 1 For bit 6, etc....
135
135
    for (int iPos = 1; iPos < (cChar + 1); iPos++)
143
143
    return ulValue;
144
144
  }
145
145
 
146
 
  t_u32 CRC32::FileCRC (const char *sFileName)
 
146
  unsigned int CRC32::FileCRC (const char *sFileName)
147
147
  {
148
 
    t_u32 ulCRC = 0xffffffff;
 
148
    unsigned int ulCRC = 0xffffffff;
149
149
 
150
150
    FILE *fSource = NULL;
151
151
    char sBuf[CRC32BUFSZ];
152
 
    t_u32 iBytesRead = 0;
 
152
    unsigned int iBytesRead = 0;
153
153
 
154
154
#ifdef WIN32_SECURE
155
155
 
163
163
 
164
164
    do
165
165
    {
166
 
      iBytesRead = (t_u32) fread (sBuf, sizeof (char), CRC32BUFSZ, fSource);
 
166
      iBytesRead = (unsigned int) fread (sBuf, sizeof (char), CRC32BUFSZ, fSource);
167
167
      PartialCRC (&ulCRC, sBuf, iBytesRead);
168
168
    }
169
169
    while (iBytesRead == CRC32BUFSZ);
174
174
  }
175
175
 
176
176
// This function uses the CRCTable lookup table to generate a CRC for sData
177
 
  t_u32 CRC32::FullCRC (const char *sData, t_u32 ulLength)
 
177
  unsigned int CRC32::FullCRC (const char *sData, unsigned int ulLength)
178
178
  {
179
 
    t_u32 ulCRC = 0xffffffff;
 
179
    unsigned int ulCRC = 0xffffffff;
180
180
    PartialCRC (&ulCRC, sData, ulLength);
181
181
    return ulCRC ^ 0xffffffff;
182
182
  }
183
183
 
184
184
// Perform the algorithm on each character
185
185
// in the string, using the lookup table values.
186
 
  void CRC32::PartialCRC (t_u32 *ulInCRC, const char *sData, t_u32 ulLength)
 
186
  void CRC32::PartialCRC (unsigned int *ulInCRC, const char *sData, unsigned int ulLength)
187
187
  {
188
188
    while (ulLength--)
189
189
    {