18c2ecf20Sopenharmony_ci/**
28c2ecf20Sopenharmony_ci * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
38c2ecf20Sopenharmony_ci * All rights reserved.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * This source code is licensed under the BSD-style license found in the
68c2ecf20Sopenharmony_ci * LICENSE file in the root directory of https://github.com/facebook/zstd.
78c2ecf20Sopenharmony_ci * An additional grant of patent rights can be found in the PATENTS file in the
88c2ecf20Sopenharmony_ci * same directory.
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify it under
118c2ecf20Sopenharmony_ci * the terms of the GNU General Public License version 2 as published by the
128c2ecf20Sopenharmony_ci * Free Software Foundation. This program is dual-licensed; you may select
138c2ecf20Sopenharmony_ci * either version 2 of the GNU General Public License ("GPL") or BSD license
148c2ecf20Sopenharmony_ci * ("BSD").
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/* Note : this module is expected to remain private, do not expose it */
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#ifndef ERROR_H_MODULE
208c2ecf20Sopenharmony_ci#define ERROR_H_MODULE
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci/* ****************************************
238c2ecf20Sopenharmony_ci*  Dependencies
248c2ecf20Sopenharmony_ci******************************************/
258c2ecf20Sopenharmony_ci#include <linux/types.h> /* size_t */
268c2ecf20Sopenharmony_ci#include <linux/zstd.h>  /* enum list */
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/* ****************************************
298c2ecf20Sopenharmony_ci*  Compiler-specific
308c2ecf20Sopenharmony_ci******************************************/
318c2ecf20Sopenharmony_ci#define ERR_STATIC static __attribute__((unused))
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci/*-****************************************
348c2ecf20Sopenharmony_ci*  Customization (error_public.h)
358c2ecf20Sopenharmony_ci******************************************/
368c2ecf20Sopenharmony_citypedef ZSTD_ErrorCode ERR_enum;
378c2ecf20Sopenharmony_ci#define PREFIX(name) ZSTD_error_##name
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/*-****************************************
408c2ecf20Sopenharmony_ci*  Error codes handling
418c2ecf20Sopenharmony_ci******************************************/
428c2ecf20Sopenharmony_ci#define ERROR(name) ((size_t)-PREFIX(name))
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ciERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ciERR_STATIC ERR_enum ERR_getErrorCode(size_t code)
478c2ecf20Sopenharmony_ci{
488c2ecf20Sopenharmony_ci	if (!ERR_isError(code))
498c2ecf20Sopenharmony_ci		return (ERR_enum)0;
508c2ecf20Sopenharmony_ci	return (ERR_enum)(0 - code);
518c2ecf20Sopenharmony_ci}
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#endif /* ERROR_H_MODULE */
54