From c48d2c5e5d05ae55474f54507d378728bbadd8d4 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 30 May 2019 00:33:02 -0700 Subject: [PATCH] Add R_TRY helper macro --- nx/include/switch/result.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nx/include/switch/result.h b/nx/include/switch/result.h index e55f25c5..904e0533 100644 --- a/nx/include/switch/result.h +++ b/nx/include/switch/result.h @@ -17,6 +17,15 @@ /// Masks out unused bits in a result code, retrieving the actual value for use in comparisons. #define R_VALUE(res) ((res)&0x3FFFFF) +/// Evaluates an expression that returns a result, and returns the result if it would fail. +#define R_TRY(res_expr) \ + do { \ + const Result _tmp_r_try_rc = res_expr; \ + if (R_FAILED(_tmp_r_try_rc)) { \ + return _tmp_r_try_rc; \ + } \ + } while (0) + /// Builds a result code from its constituent components. #define MAKERESULT(module,description) \ ((((module)&0x1FF)) | ((description)&0x1FFF)<<9)