Added Udf::calculate_crc().

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5569 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder
2003-12-04 22:59:02 +00:00
parent d220d2bb07
commit 8528b6dc19
2 changed files with 21 additions and 0 deletions
@@ -149,5 +149,24 @@ Udf::check_size_error(ssize_t bytesReturned, ssize_t bytesExpected)
: (bytesReturned >= 0 ? B_ERROR : status_t(bytesReturned));
}
/*! \brief Calculates the UDF crc checksum for the given byte stream.
Based on crc code from UDF-2.50 6.5, as permitted.
\param data Pointer to the byte stream.
\param length Length of the byte stream in bytes.
\return The crc checksum, or 0 if an error occurred.
*/
uint16
Udf::calculate_crc(uint8 *data, uint16 length)
{
uint16 crc = 0;
for ( ; length > 0; length--, data++)
crc = Udf::kCrcTable[(crc >> 8 ^ *data) & 0xff] ^ (crc << 8);
return crc;
}
} // namespace Udf
@@ -36,6 +36,8 @@ const char* bool_to_string(bool value);
status_t check_size_error(ssize_t bytesReturned, ssize_t bytesExpected);
uint16 calculate_crc(uint8 *data, uint16 length);
} // namespace Udf
#endif // _UDF_UTILS_H