convert_char.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Runtime conversion of strings from one character kind to another.
  2. Copyright (C) 2008-2015 Free Software Foundation, Inc.
  3. This file is part of the GNU Fortran runtime library (libgfortran).
  4. Libgfortran is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public
  6. License as published by the Free Software Foundation; either
  7. version 3 of the License, or (at your option) any later version.
  8. Libgfortran 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 General Public License for more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. #include "libgfortran.h"
  20. #include <stdlib.h>
  21. #include <string.h>
  22. extern void convert_char1_to_char4 (gfc_char4_t **, gfc_charlen_type,
  23. const unsigned char *);
  24. export_proto(convert_char1_to_char4);
  25. extern void convert_char4_to_char1 (unsigned char **, gfc_charlen_type,
  26. const gfc_char4_t *);
  27. export_proto(convert_char4_to_char1);
  28. void
  29. convert_char1_to_char4 (gfc_char4_t **dst, gfc_charlen_type len,
  30. const unsigned char *src)
  31. {
  32. gfc_charlen_type i, l;
  33. l = len > 0 ? len : 0;
  34. *dst = xmallocarray ((l + 1), sizeof (gfc_char4_t));
  35. for (i = 0; i < l; i++)
  36. (*dst)[i] = src[i];
  37. (*dst)[l] = '\0';
  38. }
  39. void
  40. convert_char4_to_char1 (unsigned char **dst, gfc_charlen_type len,
  41. const gfc_char4_t *src)
  42. {
  43. gfc_charlen_type i, l;
  44. l = len > 0 ? len : 0;
  45. *dst = xmalloc (l + 1);
  46. for (i = 0; i < l; i++)
  47. (*dst)[i] = src[i];
  48. (*dst)[l] = '\0';
  49. }