From 8e650c8ff7d195b5efd860da199c8d0801f065d0 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 30 May 2019 18:34:36 -0700 Subject: [PATCH] libstrat: add R_TRY helper macro. --- include/stratosphere/results.hpp | 3 +++ include/stratosphere/results/utilities.h | 25 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 include/stratosphere/results/utilities.h diff --git a/include/stratosphere/results.hpp b/include/stratosphere/results.hpp index ac352e1d..e8ac6010 100644 --- a/include/stratosphere/results.hpp +++ b/include/stratosphere/results.hpp @@ -16,6 +16,9 @@ #pragma once +/* Utilities. */ +#include "results/utilities.h" + /* Official. */ #include "results/creport_results.hpp" #include "results/debug_results.hpp" diff --git a/include/stratosphere/results/utilities.h b/include/stratosphere/results/utilities.h new file mode 100644 index 00000000..7b3a54d8 --- /dev/null +++ b/include/stratosphere/results/utilities.h @@ -0,0 +1,25 @@ +/** + * @file result_utilities.h + * @brief Utilities for handling Results. + * @author SciresM + * @copyright libnx Authors + */ +#pragma once +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/// 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) + +#ifdef __cplusplus +} +#endif