1 /* GnuTLS --- Guile bindings for GnuTLS.
2 Copyright (C) 2007-2010, 2012 Free Software Foundation, Inc.
4 GnuTLS is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 GnuTLS is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with GnuTLS; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
18 #ifndef GUILE_GNUTLS_UTILS_H
19 #define GUILE_GNUTLS_UTILS_H
21 /* Common utilities. */
26 /* Compiler twiddling. */
29 #define EXPECT __builtin_expect
30 #define NO_RETURN __attribute__ ((__noreturn__))
32 #define EXPECT(_expr, _value) (_expr)
36 #define EXPECT_TRUE(_expr) EXPECT ((_expr), 1)
37 #define EXPECT_FALSE(_expr) EXPECT ((_expr), 0)
40 /* Arrays as byte vectors. */
42 extern const char scm_gnutls_array_error_message
[];
44 /* Initialize C_HANDLE and C_LEN and return the contiguous C array
45 corresponding to ARRAY. */
46 static inline const char *
47 scm_gnutls_get_array (SCM array
, scm_t_array_handle
* c_handle
,
48 size_t * c_len
, const char *func_name
)
50 const char *c_array
= NULL
;
51 const scm_t_array_dim
*c_dims
;
53 scm_array_get_handle (array
, c_handle
);
54 c_dims
= scm_array_handle_dims (c_handle
);
55 if ((scm_array_handle_rank (c_handle
) != 1) || (c_dims
->inc
!= 1))
57 scm_array_handle_release (c_handle
);
58 scm_misc_error (func_name
, scm_gnutls_array_error_message
,
65 c_elem_size
= scm_array_handle_uniform_element_size (c_handle
);
66 *c_len
= c_elem_size
* (c_dims
->ubnd
- c_dims
->lbnd
+ 1);
68 c_array
= (char *) scm_array_handle_uniform_elements (c_handle
);
74 /* Initialize C_HANDLE and C_LEN and return the contiguous C array
75 corresponding to ARRAY. The returned array can be written to. */
77 scm_gnutls_get_writable_array (SCM array
, scm_t_array_handle
* c_handle
,
78 size_t * c_len
, const char *func_name
)
81 const scm_t_array_dim
*c_dims
;
83 scm_array_get_handle (array
, c_handle
);
84 c_dims
= scm_array_handle_dims (c_handle
);
85 if ((scm_array_handle_rank (c_handle
) != 1) || (c_dims
->inc
!= 1))
87 scm_array_handle_release (c_handle
);
88 scm_misc_error (func_name
, scm_gnutls_array_error_message
,
95 c_elem_size
= scm_array_handle_uniform_element_size (c_handle
);
96 *c_len
= c_elem_size
* (c_dims
->ubnd
- c_dims
->lbnd
+ 1);
99 (char *) scm_array_handle_uniform_writable_elements (c_handle
);
105 #define scm_gnutls_release_array scm_array_handle_release
109 /* Type conversion. */
111 /* Return a list corresponding to the key usage values ORed in C_USAGE. */
112 SCM_API SCM
scm_from_gnutls_key_usage_flags (unsigned int c_usage
);
116 /* arch-tag: a33400bc-b5e3-429e-80e0-6ff14cab79e7