From 7ad69a54269aff600620f0acf28a99f9a30461b8 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 11 Jul 2022 15:19:09 +0200 Subject: [PATCH] Introduced qmckl_last_error --- org/qmckl_error.org | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/org/qmckl_error.org b/org/qmckl_error.org index e52f429..7bbe47f 100644 --- a/org/qmckl_error.org +++ b/org/qmckl_error.org @@ -554,7 +554,44 @@ if (x < 0) { } #+end_src +* Last error + Returns a string describing the last error, using ~qmckl_get_error~. + + # Header + #+begin_src c :comments org :tangle (eval h_func) +qmckl_exit_code +qmckl_last_error(qmckl_context context, char* buffer); + #+end_src + + # Source + #+begin_src c :tangle (eval c) :exports none +qmckl_exit_code +qmckl_last_error(qmckl_context context, char* buffer) { + + char function_name[QMCKL_MAX_FUN_LEN]; + char message[QMCKL_MAX_MSG_LEN]; + + qmckl_exit_code rc, last_rc; + + if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { + strncpy(buffer, "Null context", 13); + return QMCKL_FAILURE; + } + + rc = qmckl_get_error(context, &last_rc, function_name, message); + if (rc != QMCKL_SUCCESS) { + return rc; + } + + + sprintf(buffer, "Error -- %s -- in %s\n%s", + qmckl_string_of_error(last_rc), + function_name, message); + + return QMCKL_SUCCESS; +} + #+end_src * End of files :noexport: #+begin_src c :comments link :tangle (eval h_private_type)