Check whether `-fgnu89-inline' is supported before using it.
[gnutls.git] / libextra / gnutls_extra.c
blob970208e365b272527565b2ce303ccf52f156a42e
1 /*
2 * Copyright (C) 2001, 2004, 2005, 2007, 2008 Free Software Foundation
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GNUTLS-EXTRA.
8 * GNUTLS-EXTRA is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * GNUTLS-EXTRA is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <gnutls_int.h>
23 #include <gnutls_errors.h>
24 #include <gnutls_extensions.h>
25 #include <gnutls_algorithms.h>
26 #ifdef USE_LZO
27 # ifdef USE_MINILZO
28 # include "minilzo/minilzo.h"
29 # elif HAVE_LZO_LZO1X_H
30 # include <lzo/lzo1x.h>
31 # elif HAVE_LZO1X_H
32 # include <lzo1x.h>
33 # endif
34 #endif
37 /* the number of the compression algorithms available in the compression
38 * structure.
40 extern int _gnutls_comp_algorithms_size;
42 /* Functions in gnutls that have not been initialized.
44 #ifdef USE_LZO
45 typedef int (*LZO_FUNC) ();
46 extern LZO_FUNC _gnutls_lzo1x_decompress_safe;
47 extern LZO_FUNC _gnutls_lzo1x_1_compress;
49 extern gnutls_compression_entry _gnutls_compression_algorithms[];
51 static int
52 _gnutls_add_lzo_comp (void)
54 int i;
56 /* find the last element */
57 for (i = 0; i < _gnutls_comp_algorithms_size; i++)
59 if (_gnutls_compression_algorithms[i].name == NULL)
60 break;
63 if (_gnutls_compression_algorithms[i].name == NULL
64 && (i < _gnutls_comp_algorithms_size - 1))
66 _gnutls_compression_algorithms[i].name = "GNUTLS_COMP_LZO";
67 _gnutls_compression_algorithms[i].id = GNUTLS_COMP_LZO;
68 _gnutls_compression_algorithms[i].num = 0xf2;
70 _gnutls_compression_algorithms[i + 1].name = 0;
72 /* Now enable the lzo functions: */
73 _gnutls_lzo1x_decompress_safe = lzo1x_decompress_safe;
74 _gnutls_lzo1x_1_compress = lzo1x_1_compress;
76 return 0; /* ok */
80 return GNUTLS_E_MEMORY_ERROR;
82 #endif
84 static int _gnutls_init_extra = 0;
86 /**
87 * gnutls_global_init_extra - This function initializes the global state of gnutls-extra
89 * This function initializes the global state of gnutls-extra library
90 * to defaults. Returns zero on success.
92 * Note that gnutls_global_init() has to be called before this
93 * function. If this function is not called then the gnutls-extra
94 * library will not be usable.
96 **/
97 int
98 gnutls_global_init_extra (void)
100 /* If the version of libgnutls != version of
101 * libextra, then do not initialize the library.
102 * This is because it may break things.
104 if (strcmp (gnutls_check_version (NULL), VERSION) != 0)
106 return GNUTLS_E_LIBRARY_VERSION_MISMATCH;
109 _gnutls_init_extra++;
111 if (_gnutls_init_extra != 1)
113 return 0;
116 /* Initialize the LZO library
118 #ifdef USE_LZO
120 int ret;
122 if (lzo_init () != LZO_E_OK)
124 return GNUTLS_E_LZO_INIT_FAILED;
127 /* Add the LZO compression method in the list of compression
128 * methods.
130 ret = _gnutls_add_lzo_comp ();
131 if (ret < 0)
133 gnutls_assert ();
134 return ret;
137 #endif
139 return 0;
142 #include <strverscmp.h>
145 * gnutls_extra_check_version - This function checks the library's version
146 * @req_version: the version to check
148 * Check that the version of the gnutls-extra library is at minimum
149 * the requested one and return the version string; return NULL if the
150 * condition is not satisfied. If a NULL is passed to this function,
151 * no check is done, but the version string is simply returned.
154 const char *
155 gnutls_extra_check_version (const char *req_version)
157 if (!req_version || strverscmp (req_version, VERSION) <= 0)
158 return VERSION;
160 return NULL;