Blame gettext-tools/gnulib-lib/striconveh.h

Packit Bot 06c835
/* Character set conversion with error handling.
Packit Bot 06c835
   Copyright (C) 2001-2007, 2009-2015 Free Software Foundation, Inc.
Packit Bot 06c835
   Written by Bruno Haible and Simon Josefsson.
Packit Bot 06c835
Packit Bot 06c835
   This program is free software: you can redistribute it and/or modify
Packit Bot 06c835
   it under the terms of the GNU General Public License as published by
Packit Bot 06c835
   the Free Software Foundation; either version 3 of the License, or
Packit Bot 06c835
   (at your option) any later version.
Packit Bot 06c835
Packit Bot 06c835
   This program is distributed in the hope that it will be useful,
Packit Bot 06c835
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Bot 06c835
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Bot 06c835
   GNU General Public License for more details.
Packit Bot 06c835
Packit Bot 06c835
   You should have received a copy of the GNU General Public License
Packit Bot 06c835
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Bot 06c835
Packit Bot 06c835
#ifndef _STRICONVEH_H
Packit Bot 06c835
#define _STRICONVEH_H
Packit Bot 06c835
Packit Bot 06c835
#include <stddef.h>
Packit Bot 06c835
#if HAVE_ICONV
Packit Bot 06c835
#include <iconv.h>
Packit Bot 06c835
#endif
Packit Bot 06c835
Packit Bot 06c835
#include "iconveh.h"
Packit Bot 06c835
Packit Bot 06c835
Packit Bot 06c835
#ifdef __cplusplus
Packit Bot 06c835
extern "C" {
Packit Bot 06c835
#endif
Packit Bot 06c835
Packit Bot 06c835
Packit Bot 06c835
#if HAVE_ICONV
Packit Bot 06c835
Packit Bot 06c835
/* A conversion descriptor for use by the iconveh functions.  */
Packit Bot 06c835
typedef struct
Packit Bot 06c835
  {
Packit Bot 06c835
    /* Conversion descriptor from FROM_CODESET to TO_CODESET, or (iconv_t)(-1)
Packit Bot 06c835
       if the system does not support a direct conversion from FROM_CODESET to
Packit Bot 06c835
       TO_CODESET.  */
Packit Bot 06c835
    iconv_t cd;
Packit Bot 06c835
    /* Conversion descriptor from FROM_CODESET to UTF-8 (or (iconv_t)(-1) if
Packit Bot 06c835
       FROM_CODESET is UTF-8).  */
Packit Bot 06c835
    iconv_t cd1;
Packit Bot 06c835
    /* Conversion descriptor from UTF-8 to TO_CODESET (or (iconv_t)(-1) if
Packit Bot 06c835
       TO_CODESET is UTF-8).  */
Packit Bot 06c835
    iconv_t cd2;
Packit Bot 06c835
  }
Packit Bot 06c835
  iconveh_t;
Packit Bot 06c835
Packit Bot 06c835
/* Open a conversion descriptor for use by the iconveh functions.
Packit Bot 06c835
   If successful, fills *CDP and returns 0.  Upon failure, return -1 with errno
Packit Bot 06c835
   set.  */
Packit Bot 06c835
extern int
Packit Bot 06c835
       iconveh_open (const char *to_codeset, const char *from_codeset,
Packit Bot 06c835
                     iconveh_t *cdp);
Packit Bot 06c835
Packit Bot 06c835
/* Close a conversion descriptor created by iconveh_open().
Packit Bot 06c835
   Return value: 0 if successful, otherwise -1 and errno set.  */
Packit Bot 06c835
extern int
Packit Bot 06c835
       iconveh_close (const iconveh_t *cd);
Packit Bot 06c835
Packit Bot 06c835
/* Convert an entire string from one encoding to another, using iconv.
Packit Bot 06c835
   The original string is at [SRC,...,SRC+SRCLEN-1].
Packit Bot 06c835
   CD points to the conversion descriptor from FROMCODE to TOCODE, created by
Packit Bot 06c835
   the function iconveh_open().
Packit Bot 06c835
   If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this
Packit Bot 06c835
   array is filled with offsets into the result, i.e. the character starting
Packit Bot 06c835
   at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]],
Packit Bot 06c835
   and other offsets are set to (size_t)(-1).
Packit Bot 06c835
   *RESULTP and *LENGTH should initially be a scratch buffer and its size,
Packit Bot 06c835
   or *RESULTP can initially be NULL.
Packit Bot 06c835
   May erase the contents of the memory at *RESULTP.
Packit Bot 06c835
   Return value: 0 if successful, otherwise -1 and errno set.
Packit Bot 06c835
   If successful: The resulting string is stored in *RESULTP and its length
Packit Bot 06c835
   in *LENGTHP.  *RESULTP is set to a freshly allocated memory block, or is
Packit Bot 06c835
   unchanged if no dynamic memory allocation was necessary.  */
Packit Bot 06c835
extern int
Packit Bot 06c835
       mem_cd_iconveh (const char *src, size_t srclen,
Packit Bot 06c835
                       const iconveh_t *cd,
Packit Bot 06c835
                       enum iconv_ilseq_handler handler,
Packit Bot 06c835
                       size_t *offsets,
Packit Bot 06c835
                       char **resultp, size_t *lengthp);
Packit Bot 06c835
Packit Bot 06c835
/* Convert an entire string from one encoding to another, using iconv.
Packit Bot 06c835
   The original string is the NUL-terminated string starting at SRC.
Packit Bot 06c835
   CD points to the conversion descriptor from FROMCODE to TOCODE, created by
Packit Bot 06c835
   the function iconveh_open().
Packit Bot 06c835
   Both the "from" and the "to" encoding must use a single NUL byte at the end
Packit Bot 06c835
   of the string (i.e. not UCS-2, UCS-4, UTF-16, UTF-32).
Packit Bot 06c835
   Allocate a malloced memory block for the result.
Packit Bot 06c835
   Return value: the freshly allocated resulting NUL-terminated string if
Packit Bot 06c835
   successful, otherwise NULL and errno set.  */
Packit Bot 06c835
extern char *
Packit Bot 06c835
       str_cd_iconveh (const char *src,
Packit Bot 06c835
                       const iconveh_t *cd,
Packit Bot 06c835
                       enum iconv_ilseq_handler handler);
Packit Bot 06c835
Packit Bot 06c835
#endif
Packit Bot 06c835
Packit Bot 06c835
/* Convert an entire string from one encoding to another, using iconv.
Packit Bot 06c835
   The original string is at [SRC,...,SRC+SRCLEN-1].
Packit Bot 06c835
   If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this
Packit Bot 06c835
   array is filled with offsets into the result, i.e. the character starting
Packit Bot 06c835
   at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]],
Packit Bot 06c835
   and other offsets are set to (size_t)(-1).
Packit Bot 06c835
   *RESULTP and *LENGTH should initially be a scratch buffer and its size,
Packit Bot 06c835
   or *RESULTP can initially be NULL.
Packit Bot 06c835
   May erase the contents of the memory at *RESULTP.
Packit Bot 06c835
   Return value: 0 if successful, otherwise -1 and errno set.
Packit Bot 06c835
   If successful: The resulting string is stored in *RESULTP and its length
Packit Bot 06c835
   in *LENGTHP.  *RESULTP is set to a freshly allocated memory block, or is
Packit Bot 06c835
   unchanged if no dynamic memory allocation was necessary.  */
Packit Bot 06c835
extern int
Packit Bot 06c835
       mem_iconveh (const char *src, size_t srclen,
Packit Bot 06c835
                    const char *from_codeset, const char *to_codeset,
Packit Bot 06c835
                    enum iconv_ilseq_handler handler,
Packit Bot 06c835
                    size_t *offsets,
Packit Bot 06c835
                    char **resultp, size_t *lengthp);
Packit Bot 06c835
Packit Bot 06c835
/* Convert an entire string from one encoding to another, using iconv.
Packit Bot 06c835
   The original string is the NUL-terminated string starting at SRC.
Packit Bot 06c835
   Both the "from" and the "to" encoding must use a single NUL byte at the
Packit Bot 06c835
   end of the string (i.e. not UCS-2, UCS-4, UTF-16, UTF-32).
Packit Bot 06c835
   Allocate a malloced memory block for the result.
Packit Bot 06c835
   Return value: the freshly allocated resulting NUL-terminated string if
Packit Bot 06c835
   successful, otherwise NULL and errno set.  */
Packit Bot 06c835
extern char *
Packit Bot 06c835
       str_iconveh (const char *src,
Packit Bot 06c835
                    const char *from_codeset, const char *to_codeset,
Packit Bot 06c835
                    enum iconv_ilseq_handler handler);
Packit Bot 06c835
Packit Bot 06c835
Packit Bot 06c835
#ifdef __cplusplus
Packit Bot 06c835
}
Packit Bot 06c835
#endif
Packit Bot 06c835
Packit Bot 06c835
Packit Bot 06c835
#endif /* _STRICONVEH_H */