From c75e4c25e837b6d6605c77f660fa236e89f634a0 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 10 May 2016 17:47:11 +0200 Subject: [PATCH] Added : ZSTD_getErrorString(), to get error string from error enum (#168) --- lib/common/error_private.h | 12 ++++++++---- lib/common/zstd_common.c | 6 +++++- lib/common/zstd_static.h | 3 ++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/common/error_private.h b/lib/common/error_private.h index 7bd03065b..3f039ae67 100644 --- a/lib/common/error_private.h +++ b/lib/common/error_private.h @@ -78,17 +78,17 @@ typedef ZSTD_ErrorCode ERR_enum; ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } -ERR_STATIC ERR_enum ERR_getError(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); } +ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); } /*-**************************************** * Error Strings ******************************************/ -ERR_STATIC const char* ERR_getErrorName(size_t code) +ERR_STATIC const char* ERR_getErrorString(ERR_enum code) { static const char* notErrorCode = "Unspecified error code"; - switch( ERR_getError(code) ) + switch( code ) { case PREFIX(no_error): return "No error detected"; case PREFIX(GENERIC): return "Error (generic)"; @@ -107,10 +107,14 @@ ERR_STATIC const char* ERR_getErrorName(size_t code) case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small"; case PREFIX(dictionary_corrupted): return "Dictionary is corrupted"; case PREFIX(maxCode): - default: return notErrorCode; /* impossible, due to ERR_getError() */ + default: return notErrorCode; } } +ERR_STATIC const char* ERR_getErrorName(size_t code) +{ + return ERR_getErrorString(ERR_getErrorCode(code)); +} #if defined (__cplusplus) } diff --git a/lib/common/zstd_common.c b/lib/common/zstd_common.c index 679e3ace6..9915da759 100644 --- a/lib/common/zstd_common.c +++ b/lib/common/zstd_common.c @@ -52,12 +52,16 @@ unsigned ZSTD_isError(size_t code) { return ERR_isError(code); } /*! ZSTD_getError() : * convert a `size_t` function result into a proper ZSTD_errorCode enum */ -ZSTD_ErrorCode ZSTD_getError(size_t code) { return ERR_getError(code); } +ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); } /*! ZSTD_getErrorName() : * provides error code string (useful for debugging) */ const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); } +/*! ZSTD_getErrorName() : +* provides error code string (useful for debugging) */ +const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorName(code); } + /*-**************************************** * FSE Error Management diff --git a/lib/common/zstd_static.h b/lib/common/zstd_static.h index 0ec5b635c..ef42b0a97 100644 --- a/lib/common/zstd_static.h +++ b/lib/common/zstd_static.h @@ -261,7 +261,8 @@ ZSTDLIB_API size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_t dstCa /*! ZSTD_getErrorCode() : convert a `size_t` function result into a `ZSTD_ErrorCode` enum type, which can be used to compare directly with enum list published into "error_public.h" */ -ZSTDLIB_API ZSTD_ErrorCode ZSTD_getError(size_t code); +ZSTDLIB_API ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult); +ZSTDLIB_API const char* ZSTD_getErrorString(ZSTD_ErrorCode code); #if defined (__cplusplus) -- 2.47.2