Debian Codegraph @

guile/src/errors.c

raw
1 /* GnuTLS --- Guile bindings for GnuTLS.
2 Copyright (C) 2007-2025 Free Software Foundation, Inc.
3
4 This file is part of Guile-GnuTLS.
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with this library; if not, see <https://www.gnu.org/licenses/>. */
18
19 /* Written by Ludovic Courtès <[email protected]>. */
20
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24
25 #include <libguile.h>
26 #include <gnutls/gnutls.h>
27 #include <gnutls/crypto.h>
28
29 #include "errors.h"
30 #include "enums.h"
31
32 SCM_SYMBOL (gnutls_error_key, "gnutls-error");
33
34 void
35 scm_gnutls_error_with_args (int c_err, const char *c_func, SCM args)
36 {
37 SCM err, func;
38
39 /* Note: If error code C_ERR is unknown, then ERR will be `#f'. */
40 err = scm_from_gnutls_error (c_err);
41 func = scm_from_locale_symbol (c_func);
42
43 (void) scm_throw (gnutls_error_key, scm_cons2 (err, func, args));
44
45 /* XXX: This is actually never reached, but since the Guile headers don't
46 declare `scm_throw ()' as `noreturn', we must add this to avoid GCC's
47 complaints. */
48 abort ();
49 }
50
51 void
52 scm_gnutls_error (int c_err, const char *c_func)
53 {
54 scm_gnutls_error_with_args (c_err, c_func, SCM_EOL);
55 }
56
57 SCM_DEFINE (scm_gnutls_fatal_error_p, "fatal-error?", 1, 0, 0,
58 (SCM err), "Return true if @var{error} is fatal.")
59 #define FUNC_NAME s_scm_gnutls_fatal_error_p
60 {
61 int c_err = scm_to_gnutls_error (err, 1, FUNC_NAME);
62 return scm_from_bool (gnutls_error_is_fatal (c_err));
63 }
64
65 #undef FUNC_NAME
66
67
68
69 void
70 scm_init_gnutls_error (void)
71 {
72 #include "errors.x"
73 }
74
75 /* arch-tag: 48f07ecf-65c4-480c-b043-a51eab592d6b
76 */