libstrat: add R_TRY helper macro.

This commit is contained in:
Michael Scire 2019-05-30 18:34:36 -07:00
parent 1477f2d634
commit 8e650c8ff7
2 changed files with 28 additions and 0 deletions

View File

@ -16,6 +16,9 @@
#pragma once
/* Utilities. */
#include "results/utilities.h"
/* Official. */
#include "results/creport_results.hpp"
#include "results/debug_results.hpp"

View File

@ -0,0 +1,25 @@
/**
* @file result_utilities.h
* @brief Utilities for handling Results.
* @author SciresM
* @copyright libnx Authors
*/
#pragma once
#include <switch/result.h>
#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