1aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// Copyright 2014 Google Inc.
2aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// All rights reserved.
3aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org//
4aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// Redistribution and use in source and binary forms, with or without
5aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// modification, are permitted provided that the following conditions are
6aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// met:
7aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org//
8aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org//     * Redistributions of source code must retain the above copyright
9aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// notice, this list of conditions and the following disclaimer.
10aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org//     * Redistributions in binary form must reproduce the above
11aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// copyright notice, this list of conditions and the following disclaimer
12aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// in the documentation and/or other materials provided with the
13aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// distribution.
14aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org//     * Neither the name of Google Inc. nor the names of its
15aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// contributors may be used to endorse or promote products derived from
16aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// this software without specific prior written permission.
17aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org//
18aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org
30aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org#ifndef COMMON_LINUX_CRC32_H_
31aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org#define COMMON_LINUX_CRC32_H_
32aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org
33aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org#include <stdint.h>
34aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org
35aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org#include <string>
36aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org
37aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.orgnamespace google_breakpad {
38aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org
39aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// Updates a CRC32 checksum with |len| bytes from |buf|. |initial| holds the
40aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// checksum result from the previous update; for the first call, it should be 0.
41aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.orguint32_t UpdateCrc32(uint32_t initial, const void* buf, size_t len);
42aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org
43aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org// Computes a CRC32 checksum using |len| bytes from |buf|.
44aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.orginline uint32_t ComputeCrc32(const void* buf, size_t len) {
45aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org  return UpdateCrc32(0, buf, len);
46aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org}
47aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.orginline uint32_t ComputeCrc32(const std::string& str) {
48aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org  return ComputeCrc32(str.c_str(), str.size());
49aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org}
50aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org
51aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org}  // namespace google_breakpad
52aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org
53aca3b55bfab9c1aee660716ec0f1850e06005882thestig@chromium.org#endif  // COMMON_LINUX_CRC32_H_
54