Blame lib/xstriconv.h

Packit 33f14e
/* Charset conversion with out-of-memory checking.
Packit 33f14e
   Copyright (C) 2001-2004, 2006-2007, 2009-2017 Free Software Foundation, Inc.
Packit 33f14e
   Written by Bruno Haible and Simon Josefsson.
Packit 33f14e
Packit 33f14e
   This program is free software: you can redistribute it and/or modify
Packit 33f14e
   it under the terms of the GNU General Public License as published by
Packit 33f14e
   the Free Software Foundation; either version 3 of the License, or
Packit 33f14e
   (at your option) any later version.
Packit 33f14e
Packit 33f14e
   This program is distributed in the hope that it will be useful,
Packit 33f14e
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 33f14e
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 33f14e
   GNU General Public License for more details.
Packit 33f14e
Packit 33f14e
   You should have received a copy of the GNU General Public License
Packit 33f14e
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 33f14e
Packit 33f14e
#ifndef _XSTRICONV_H
Packit 33f14e
#define _XSTRICONV_H
Packit 33f14e
Packit 33f14e
#include <stddef.h>
Packit 33f14e
#if HAVE_ICONV
Packit 33f14e
#include <iconv.h>
Packit 33f14e
#endif
Packit 33f14e
Packit 33f14e
Packit 33f14e
#ifdef __cplusplus
Packit 33f14e
extern "C" {
Packit 33f14e
#endif
Packit 33f14e
Packit 33f14e
Packit 33f14e
#if HAVE_ICONV
Packit 33f14e
Packit 33f14e
/* Convert an entire string from one encoding to another, using iconv.
Packit 33f14e
   The original string is at [SRC,...,SRC+SRCLEN-1].
Packit 33f14e
   The conversion descriptor is passed as CD.
Packit 33f14e
   *RESULTP and *LENGTH should initially be a scratch buffer and its size,
Packit 33f14e
   or *RESULTP can initially be NULL.
Packit 33f14e
   May erase the contents of the memory at *RESULTP.
Packit 33f14e
   Upon memory allocation failure, report the error and exit.
Packit 33f14e
   Return value: 0 if successful, otherwise -1 and errno set.
Packit 33f14e
   If successful: The resulting string is stored in *RESULTP and its length
Packit 33f14e
   in *LENGTHP.  *RESULTP is set to a freshly allocated memory block, or is
Packit 33f14e
   unchanged if no dynamic memory allocation was necessary.  */
Packit 33f14e
extern int xmem_cd_iconv (const char *src, size_t srclen, iconv_t cd,
Packit 33f14e
                          char **resultp, size_t *lengthp);
Packit 33f14e
Packit 33f14e
/* Convert an entire string from one encoding to another, using iconv.
Packit 33f14e
   The original string is the NUL-terminated string starting at SRC.
Packit 33f14e
   The conversion descriptor is passed as CD.  Both the "from" and the "to"
Packit 33f14e
   encoding must use a single NUL byte at the end of the string (i.e. not
Packit 33f14e
   UCS-2, UCS-4, UTF-16, UTF-32).
Packit 33f14e
   Allocate a malloced memory block for the result.
Packit 33f14e
   Upon memory allocation failure, report the error and exit.
Packit 33f14e
   Return value: the freshly allocated resulting NUL-terminated string if
Packit 33f14e
   successful, otherwise NULL and errno set.  */
Packit 33f14e
extern char * xstr_cd_iconv (const char *src, iconv_t cd);
Packit 33f14e
Packit 33f14e
#endif
Packit 33f14e
Packit 33f14e
/* Convert an entire string from one encoding to another, using iconv.
Packit 33f14e
   The original string is the NUL-terminated string starting at SRC.
Packit 33f14e
   Both the "from" and the "to" encoding must use a single NUL byte at the
Packit 33f14e
   end of the string (i.e. not UCS-2, UCS-4, UTF-16, UTF-32).
Packit 33f14e
   Allocate a malloced memory block for the result.
Packit 33f14e
   Upon memory allocation failure, report the error and exit.
Packit 33f14e
   Return value: the freshly allocated resulting NUL-terminated string if
Packit 33f14e
   successful, otherwise NULL and errno set.  */
Packit 33f14e
extern char * xstr_iconv (const char *src,
Packit 33f14e
                          const char *from_codeset, const char *to_codeset);
Packit 33f14e
Packit 33f14e
Packit 33f14e
#ifdef __cplusplus
Packit 33f14e
}
Packit 33f14e
#endif
Packit 33f14e
Packit 33f14e
Packit 33f14e
#endif /* _XSTRICONV_H */