aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/zstd/zstd_common.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-09-08 16:59:45 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-09-08 17:00:14 +0100
commitbd10330aa73c9f6eab293b38cf1c86e03fe46fa1 (patch)
treed82e7505b0903a9155f35202e486455066826b1e /contrib/zstd/zstd_common.c
parente3c5642da397104ed4d5c0171353e997f4ceba77 (diff)
downloadrspamd-bd10330aa73c9f6eab293b38cf1c86e03fe46fa1.tar.gz
rspamd-bd10330aa73c9f6eab293b38cf1c86e03fe46fa1.zip
[Feature] Add zstd compression library
Diffstat (limited to 'contrib/zstd/zstd_common.c')
-rw-r--r--contrib/zstd/zstd_common.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/contrib/zstd/zstd_common.c b/contrib/zstd/zstd_common.c
new file mode 100644
index 000000000..54bc91c89
--- /dev/null
+++ b/contrib/zstd/zstd_common.c
@@ -0,0 +1,83 @@
+/**
+ * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
+ * All rights reserved.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
+ */
+
+
+
+/*-*************************************
+* Dependencies
+***************************************/
+#include <stdlib.h> /* malloc */
+#include "error_private.h"
+#define ZSTD_STATIC_LINKING_ONLY
+#include "zstd.h" /* declaration of ZSTD_isError, ZSTD_getErrorName, ZSTD_getErrorCode, ZSTD_getErrorString, ZSTD_versionNumber */
+#include "zbuff.h" /* declaration of ZBUFF_isError, ZBUFF_getErrorName */
+
+
+/*-****************************************
+* Version
+******************************************/
+unsigned ZSTD_versionNumber (void) { return ZSTD_VERSION_NUMBER; }
+
+
+/*-****************************************
+* ZSTD Error Management
+******************************************/
+/*! ZSTD_isError() :
+* tells if a return value is an error code */
+unsigned ZSTD_isError(size_t code) { return ERR_isError(code); }
+
+/*! ZSTD_getErrorName() :
+* provides error code string from function result (useful for debugging) */
+const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); }
+
+/*! ZSTD_getError() :
+* convert a `size_t` function result into a proper ZSTD_errorCode enum */
+ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
+
+/*! ZSTD_getErrorString() :
+* provides error code string from enum */
+const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorName(code); }
+
+
+/* **************************************************************
+* ZBUFF Error Management
+****************************************************************/
+unsigned ZBUFF_isError(size_t errorCode) { return ERR_isError(errorCode); }
+
+const char* ZBUFF_getErrorName(size_t errorCode) { return ERR_getErrorName(errorCode); }
+
+
+
+/*=**************************************************************
+* Custom allocator
+****************************************************************/
+/* default uses stdlib */
+void* ZSTD_defaultAllocFunction(void* opaque, size_t size)
+{
+ void* address = malloc(size);
+ (void)opaque;
+ return address;
+}
+
+void ZSTD_defaultFreeFunction(void* opaque, void* address)
+{
+ (void)opaque;
+ free(address);
+}
+
+void* ZSTD_malloc(size_t size, ZSTD_customMem customMem)
+{
+ return customMem.customAlloc(customMem.opaque, size);
+}
+
+void ZSTD_free(void* ptr, ZSTD_customMem customMem)
+{
+ if (ptr!=NULL)
+ customMem.customFree(customMem.opaque, ptr);
+}