~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/lib/zstd/common/error_private.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Copyright (c) Yann Collet, Facebook, Inc.
  3  * All rights reserved.
  4  *
  5  * This source code is licensed under both the BSD-style license (found in the
  6  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
  7  * in the COPYING file in the root directory of this source tree).
  8  * You may select, at your option, one of the above-listed licenses.
  9  */
 10 
 11 /* Note : this module is expected to remain private, do not expose it */
 12 
 13 #ifndef ERROR_H_MODULE
 14 #define ERROR_H_MODULE
 15 
 16 
 17 
 18 /* ****************************************
 19 *  Dependencies
 20 ******************************************/
 21 #include <linux/zstd_errors.h>  /* enum list */
 22 #include "compiler.h"
 23 #include "debug.h"
 24 #include "zstd_deps.h"       /* size_t */
 25 
 26 
 27 /* ****************************************
 28 *  Compiler-specific
 29 ******************************************/
 30 #define ERR_STATIC static __attribute__((unused))
 31 
 32 
 33 /*-****************************************
 34 *  Customization (error_public.h)
 35 ******************************************/
 36 typedef ZSTD_ErrorCode ERR_enum;
 37 #define PREFIX(name) ZSTD_error_##name
 38 
 39 
 40 /*-****************************************
 41 *  Error codes handling
 42 ******************************************/
 43 #undef ERROR   /* already defined on Visual Studio */
 44 #define ERROR(name) ZSTD_ERROR(name)
 45 #define ZSTD_ERROR(name) ((size_t)-PREFIX(name))
 46 
 47 ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
 48 
 49 ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
 50 
 51 /* check and forward error code */
 52 #define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e
 53 #define CHECK_F(f)   { CHECK_V_F(_var_err__, f); }
 54 
 55 
 56 /*-****************************************
 57 *  Error Strings
 58 ******************************************/
 59 
 60 const char* ERR_getErrorString(ERR_enum code);   /* error_private.c */
 61 
 62 ERR_STATIC const char* ERR_getErrorName(size_t code)
 63 {
 64     return ERR_getErrorString(ERR_getErrorCode(code));
 65 }
 66 
 67 /*
 68  * Ignore: this is an internal helper.
 69  *
 70  * This is a helper function to help force C99-correctness during compilation.
 71  * Under strict compilation modes, variadic macro arguments can't be empty.
 72  * However, variadic function arguments can be. Using a function therefore lets
 73  * us statically check that at least one (string) argument was passed,
 74  * independent of the compilation flags.
 75  */
 76 static INLINE_KEYWORD UNUSED_ATTR
 77 void _force_has_format_string(const char *format, ...) {
 78   (void)format;
 79 }
 80 
 81 /*
 82  * Ignore: this is an internal helper.
 83  *
 84  * We want to force this function invocation to be syntactically correct, but
 85  * we don't want to force runtime evaluation of its arguments.
 86  */
 87 #define _FORCE_HAS_FORMAT_STRING(...) \
 88   if (0) { \
 89     _force_has_format_string(__VA_ARGS__); \
 90   }
 91 
 92 #define ERR_QUOTE(str) #str
 93 
 94 /*
 95  * Return the specified error if the condition evaluates to true.
 96  *
 97  * In debug modes, prints additional information.
 98  * In order to do that (particularly, printing the conditional that failed),
 99  * this can't just wrap RETURN_ERROR().
100  */
101 #define RETURN_ERROR_IF(cond, err, ...) \
102   if (cond) { \
103     RAWLOG(3, "%s:%d: ERROR!: check %s failed, returning %s", \
104            __FILE__, __LINE__, ERR_QUOTE(cond), ERR_QUOTE(ERROR(err))); \
105     _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
106     RAWLOG(3, ": " __VA_ARGS__); \
107     RAWLOG(3, "\n"); \
108     return ERROR(err); \
109   }
110 
111 /*
112  * Unconditionally return the specified error.
113  *
114  * In debug modes, prints additional information.
115  */
116 #define RETURN_ERROR(err, ...) \
117   do { \
118     RAWLOG(3, "%s:%d: ERROR!: unconditional check failed, returning %s", \
119            __FILE__, __LINE__, ERR_QUOTE(ERROR(err))); \
120     _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
121     RAWLOG(3, ": " __VA_ARGS__); \
122     RAWLOG(3, "\n"); \
123     return ERROR(err); \
124   } while(0);
125 
126 /*
127  * If the provided expression evaluates to an error code, returns that error code.
128  *
129  * In debug modes, prints additional information.
130  */
131 #define FORWARD_IF_ERROR(err, ...) \
132   do { \
133     size_t const err_code = (err); \
134     if (ERR_isError(err_code)) { \
135       RAWLOG(3, "%s:%d: ERROR!: forwarding error in %s: %s", \
136              __FILE__, __LINE__, ERR_QUOTE(err), ERR_getErrorName(err_code)); \
137       _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
138       RAWLOG(3, ": " __VA_ARGS__); \
139       RAWLOG(3, "\n"); \
140       return err_code; \
141     } \
142   } while(0);
143 
144 
145 #endif /* ERROR_H_MODULE */
146 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php