1 /** 2 * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. 3 * All rights reserved. 4 * 5 * This source code is licensed under the BSD-style license found in the 6 * LICENSE file in the root directory of https://github.com/facebook/zstd. 7 * 8 * This program is free software; you can redistribute it and/or modify it under 9 * the terms of the GNU General Public License version 2 as published by the 10 * Free Software Foundation. This program is dual-licensed; you may select 11 * either version 2 of the GNU General Public License ("GPL") or BSD license 12 * ("BSD"). 13 */ 14 15 /* Note : this module is expected to remain private, do not expose it */ 16 17 #ifndef ERROR_H_MODULE 18 #define ERROR_H_MODULE 19 20 /* **************************************** 21 * Dependencies 22 ******************************************/ 23 #include <linux/types.h> /* size_t */ 24 #include <linux/zstd.h> /* enum list */ 25 26 /* **************************************** 27 * Compiler-specific 28 ******************************************/ 29 #define ERR_STATIC static __attribute__((unused)) 30 31 /*-**************************************** 32 * Customization (error_public.h) 33 ******************************************/ 34 typedef ZSTD_ErrorCode ERR_enum; 35 #define PREFIX(name) ZSTD_error_##name 36 37 /*-**************************************** 38 * Error codes handling 39 ******************************************/ 40 #define ERROR(name) ((size_t)-PREFIX(name)) 41 ERR_isError(size_t code)42ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } 43 ERR_getErrorCode(size_t code)44ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) 45 { 46 if (!ERR_isError(code)) 47 return (ERR_enum)0; 48 return (ERR_enum)(0 - code); 49 } 50 51 #endif /* ERROR_H_MODULE */ 52