1 /* SPDX-License-Identifier: (GPL-2.0 or BSD-3-Clause-Clear) */ 2 /** 3 * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. 4 * All rights reserved. 5 */ 6 7 /* Note : this module is expected to remain private, do not expose it */ 8 9 #ifndef ERROR_H_MODULE 10 #define ERROR_H_MODULE 11 12 /* **************************************** 13 * Dependencies 14 ******************************************/ 15 #include <linux/types.h> /* size_t */ 16 #include <linux/zstd.h> /* enum list */ 17 18 /* **************************************** 19 * Compiler-specific 20 ******************************************/ 21 #define ERR_STATIC static __attribute__((unused)) 22 23 /*-**************************************** 24 * Customization (error_public.h) 25 ******************************************/ 26 typedef ZSTD_ErrorCode ERR_enum; 27 #define PREFIX(name) ZSTD_error_##name 28 29 /*-**************************************** 30 * Error codes handling 31 ******************************************/ 32 #define ERROR(name) ((size_t)-PREFIX(name)) 33 ERR_isError(size_t code)34ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } 35 ERR_getErrorCode(size_t code)36ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) 37 { 38 if (!ERR_isError(code)) 39 return (ERR_enum)0; 40 return (ERR_enum)(0 - code); 41 } 42 43 #endif /* ERROR_H_MODULE */ 44