striconv.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Charset conversion.
  2. Copyright (C) 2001-2004, 2006-2007, 2009-2024 Free Software Foundation, Inc.
  3. Written by Bruno Haible and Simon Josefsson.
  4. This file is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as
  6. published by the Free Software Foundation; either version 2.1 of the
  7. License, or (at your option) any later version.
  8. This file is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  14. #ifndef _STRICONV_H
  15. #define _STRICONV_H
  16. /* This file uses _GL_ATTRIBUTE_MALLOC, HAVE_ICONV. */
  17. #if !_GL_CONFIG_H_INCLUDED
  18. #error "Please include config.h first."
  19. #endif
  20. #include <stdlib.h>
  21. #if HAVE_ICONV
  22. #include <iconv.h>
  23. #endif
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #if HAVE_ICONV
  28. /* Convert an entire string from one encoding to another, using iconv.
  29. The original string is at [SRC,...,SRC+SRCLEN-1].
  30. The conversion descriptor is passed as CD.
  31. *RESULTP and *LENGTH should initially be a scratch buffer and its size,
  32. or *RESULTP can initially be NULL.
  33. May erase the contents of the memory at *RESULTP.
  34. Return value: 0 if successful, otherwise -1 and errno set.
  35. If successful: The resulting string is stored in *RESULTP and its length
  36. in *LENGTHP. *RESULTP is set to a freshly allocated memory block, or is
  37. unchanged if no dynamic memory allocation was necessary. */
  38. extern int mem_cd_iconv (const char *src, size_t srclen, iconv_t cd,
  39. char **resultp, size_t *lengthp);
  40. /* Convert an entire string from one encoding to another, using iconv.
  41. The original string is the NUL-terminated string starting at SRC.
  42. The conversion descriptor is passed as CD. Both the "from" and the "to"
  43. encoding must use a single NUL byte at the end of the string (i.e. not
  44. UCS-2, UCS-4, UTF-16, UTF-32).
  45. Allocate a malloced memory block for the result.
  46. Return value: the freshly allocated resulting NUL-terminated string if
  47. successful, otherwise NULL and errno set. */
  48. extern char * str_cd_iconv (const char *src, iconv_t cd)
  49. _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
  50. #endif
  51. /* Convert an entire string from one encoding to another, using iconv.
  52. The original string is the NUL-terminated string starting at SRC.
  53. Both the "from" and the "to" encoding must use a single NUL byte at the
  54. end of the string (i.e. not UCS-2, UCS-4, UTF-16, UTF-32).
  55. Allocate a malloced memory block for the result.
  56. Return value: the freshly allocated resulting NUL-terminated string if
  57. successful, otherwise NULL and errno set. */
  58. extern char * str_iconv (const char *src,
  59. const char *from_codeset, const char *to_codeset)
  60. _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. #endif /* _STRICONV_H */