Fix build.
[chromium-blink-merge.git] / rlz / lib / crc32_wrapper.cc
blobd763c265c9f46fe588bee1b9cebd3aa2514e1ccf
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // A wrapper around ZLib's CRC functions to put them in the rlz_lib namespace
6 // and use our types.
8 #include "rlz/lib/assert.h"
9 #include "rlz/lib/crc32.h"
10 #include "rlz/lib/string_utils.h"
11 #include "third_party/zlib/zlib.h"
13 namespace rlz_lib {
15 int Crc32(const unsigned char* buf, int length) {
16 return crc32(0L, buf, length);
19 bool Crc32(const char* text, int* crc) {
20 if (!crc) {
21 ASSERT_STRING("Crc32: crc is NULL.");
22 return false;
25 *crc = 0;
26 for (int i = 0; text[i]; i++) {
27 if (!IsAscii(text[i]))
28 return false;
30 *crc = crc32(*crc, reinterpret_cast<const unsigned char*>(text + i), 1);
33 return true;
36 } // namespace rlz_lib