maint: update copyright
[gnulib.git] / lib / xstriconveh.c
1 /* Charset conversion with out-of-memory checking.
2    Copyright (C) 2009-2014 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 3 of the License, or
8    (at your option) 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, see <http://www.gnu.org/licenses/>.  */
17
18 #include <config.h>
19
20 /* Specification.  */
21 #include "xstriconveh.h"
22
23 #include <errno.h>
24
25 #include "striconveh.h"
26 #include "xalloc.h"
27
28
29 #if HAVE_ICONV
30
31 int
32 xmem_cd_iconveh (const char *src, size_t srclen,
33                  const iconveh_t *cd,
34                  enum iconv_ilseq_handler handler,
35                  size_t *offsets,
36                  char **resultp, size_t *lengthp)
37 {
38   int retval =
39     mem_cd_iconveh (src, srclen, cd, handler, offsets, resultp, lengthp);
40
41   if (retval < 0 && errno == ENOMEM)
42     xalloc_die ();
43   return retval;
44 }
45
46 char *
47 xstr_cd_iconveh (const char *src,
48                  const iconveh_t *cd,
49                  enum iconv_ilseq_handler handler)
50 {
51   char *result = str_cd_iconveh (src, cd, handler);
52
53   if (result == NULL && errno == ENOMEM)
54     xalloc_die ();
55   return result;
56 }
57
58 #endif
59
60 int
61 xmem_iconveh (const char *src, size_t srclen,
62               const char *from_codeset, const char *to_codeset,
63               enum iconv_ilseq_handler handler,
64               size_t *offsets,
65               char **resultp, size_t *lengthp)
66 {
67   int retval =
68     mem_iconveh (src, srclen, from_codeset, to_codeset, handler, offsets,
69                  resultp, lengthp);
70
71   if (retval < 0 && errno == ENOMEM)
72     xalloc_die ();
73   return retval;
74 }
75
76 char *
77 xstr_iconveh (const char *src,
78               const char *from_codeset, const char *to_codeset,
79               enum iconv_ilseq_handler handler)
80 {
81   char *result = str_iconveh (src, from_codeset, to_codeset, handler);
82
83   if (result == NULL && errno == ENOMEM)
84     xalloc_die ();
85   return result;
86 }