Skip to content

Instantly share code, notes, and snippets.

@LadyNamedLaura
Created December 4, 2012 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LadyNamedLaura/4205747 to your computer and use it in GitHub Desktop.
Save LadyNamedLaura/4205747 to your computer and use it in GitHub Desktop.
THROW_CALL macro for use with functions that return a negative errno-style error code
diff -uNr p99-2012-12-03/p99/p99_try.h p99/p99/p99_try.h
--- p99-2012-12-03/p99/p99_try.h 2012-12-03 13:40:29.000000000 +0100
+++ p99/p99/p99_try.h 2012-12-04 17:13:46.116666909 +0100
@@ -345,6 +345,20 @@
#define P00_THROW_CALL_NEG(F, E, ...) \
p00_throw_call_neg(F(__VA_ARGS__), E, p00_unwind_top, P99_STRINGIFY(__LINE__), __func__, #F ", neg return")
+p99_inline
+int p00_throw_call_neg_errno(int p00_neg_errno,
+ errno_t p00_def,
+ p00_jmp_buf0 * p00_top,
+ char const* p00_file,
+ char const* p00_context,
+ char const* p00_info) {
+ if (P99_UNLIKELY(p00_neg < 0)) p00_jmp_throw(-p00_neg, p00_top, p00_file, p00_context, p00_info);
+ return p00_neg;
+}
+
+#define P00_THROW_CALL_NEG(F, E, ...) \
+p00_throw_call_neg_errno(F(__VA_ARGS__), E, p00_unwind_top, P99_STRINGIFY(__LINE__), __func__, #F ", neg return")
+
/**
** @brief Wrap a function call to @a F such that it throws an error
** on negative return.
@@ -365,6 +379,7 @@
** pointer return value
**/
#define P99_THROW_CALL_NEG(F, E, ...) P00_THROW_CALL_NEG(F, E, __VA_ARGS__)
+#define P99_THROW_CALL_NEG_ERRNO(F, E, ...) P00_THROW_CALL_NEG_ERRNO(F, E, __VA_ARGS__)
p99_inline
void* p00_throw_call_voidp(void* p00_p,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment