1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/other-licenses/snappy/src/snappy-c.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 +// Copyright 2011 Martin Gieseking <martin.gieseking@uos.de>. 1.5 +// 1.6 +// Redistribution and use in source and binary forms, with or without 1.7 +// modification, are permitted provided that the following conditions are 1.8 +// met: 1.9 +// 1.10 +// * Redistributions of source code must retain the above copyright 1.11 +// notice, this list of conditions and the following disclaimer. 1.12 +// * Redistributions in binary form must reproduce the above 1.13 +// copyright notice, this list of conditions and the following disclaimer 1.14 +// in the documentation and/or other materials provided with the 1.15 +// distribution. 1.16 +// * Neither the name of Google Inc. nor the names of its 1.17 +// contributors may be used to endorse or promote products derived from 1.18 +// this software without specific prior written permission. 1.19 +// 1.20 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.21 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.22 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.23 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.24 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.25 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.26 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.27 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.28 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.29 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.30 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.31 + 1.32 +#include "snappy.h" 1.33 +#include "snappy-c.h" 1.34 + 1.35 +extern "C" { 1.36 + 1.37 +snappy_status snappy_compress(const char* input, 1.38 + size_t input_length, 1.39 + char* compressed, 1.40 + size_t *compressed_length) { 1.41 + if (*compressed_length < snappy_max_compressed_length(input_length)) { 1.42 + return SNAPPY_BUFFER_TOO_SMALL; 1.43 + } 1.44 + snappy::RawCompress(input, input_length, compressed, compressed_length); 1.45 + return SNAPPY_OK; 1.46 +} 1.47 + 1.48 +snappy_status snappy_uncompress(const char* compressed, 1.49 + size_t compressed_length, 1.50 + char* uncompressed, 1.51 + size_t* uncompressed_length) { 1.52 + size_t real_uncompressed_length; 1.53 + if (!snappy::GetUncompressedLength(compressed, 1.54 + compressed_length, 1.55 + &real_uncompressed_length)) { 1.56 + return SNAPPY_INVALID_INPUT; 1.57 + } 1.58 + if (*uncompressed_length < real_uncompressed_length) { 1.59 + return SNAPPY_BUFFER_TOO_SMALL; 1.60 + } 1.61 + if (!snappy::RawUncompress(compressed, compressed_length, uncompressed)) { 1.62 + return SNAPPY_INVALID_INPUT; 1.63 + } 1.64 + *uncompressed_length = real_uncompressed_length; 1.65 + return SNAPPY_OK; 1.66 +} 1.67 + 1.68 +size_t snappy_max_compressed_length(size_t source_length) { 1.69 + return snappy::MaxCompressedLength(source_length); 1.70 +} 1.71 + 1.72 +snappy_status snappy_uncompressed_length(const char *compressed, 1.73 + size_t compressed_length, 1.74 + size_t *result) { 1.75 + if (snappy::GetUncompressedLength(compressed, 1.76 + compressed_length, 1.77 + result)) { 1.78 + return SNAPPY_OK; 1.79 + } else { 1.80 + return SNAPPY_INVALID_INPUT; 1.81 + } 1.82 +} 1.83 + 1.84 +snappy_status snappy_validate_compressed_buffer(const char *compressed, 1.85 + size_t compressed_length) { 1.86 + if (snappy::IsValidCompressedBuffer(compressed, compressed_length)) { 1.87 + return SNAPPY_OK; 1.88 + } else { 1.89 + return SNAPPY_INVALID_INPUT; 1.90 + } 1.91 +} 1.92 + 1.93 +} // extern "C"