Include <config.h> unconditionally.
[gnulib.git] / lib / xstriconv.c
1 /* Charset conversion with out-of-memory checking.
2    Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc.
3    Written by Bruno Haible.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2, or (at your option)
8    any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software Foundation,
17    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
18
19 #include <config.h>
20
21 /* Specification.  */
22 #include "xstriconv.h"
23
24 #include <errno.h>
25
26 #include "striconv.h"
27 #include "xalloc.h"
28
29
30 #if HAVE_ICONV
31
32 int
33 xmem_cd_iconv (const char *src, size_t srclen, iconv_t cd,
34                char **resultp, size_t *lengthp)
35 {
36   int retval = mem_cd_iconv (src, srclen, cd, resultp, lengthp);
37
38   if (retval < 0 && errno == ENOMEM)
39     xalloc_die ();
40   return retval;
41 }
42
43 char *
44 xstr_cd_iconv (const char *src, iconv_t cd)
45 {
46   char *result = str_cd_iconv (src, cd);
47
48   if (result == NULL && errno == ENOMEM)
49     xalloc_die ();
50   return result;
51 }
52
53 #endif
54
55 char *
56 xstr_iconv (const char *src, const char *from_codeset, const char *to_codeset)
57 {
58   char *result = str_iconv (src, from_codeset, to_codeset);
59
60   if (result == NULL && errno == ENOMEM)
61     xalloc_die ();
62   return result;
63 }